C Function Description and Parameters

Source: Internet
Author: User

<1> function declaration

I recently read the C language, which is very confusing. In some cases, function declaration is not available in some cases.

I checked the teaching material, made a summary, copied the pen, and recorded it online. I have forgotten it!

 

Function declaration is not required in the following three cases:

1. If the return type of the called function is integer or char, the system will take care of it.

Example:

// Code 1 # include <stdio. h> int main () {int A = 30; double D = 4.4334; printf ("A = % d", call (a); Return 0 ;} int call (INT d) {printf ("helloworld \ n"); Return D ;}

Correct. What if I change the return type of the call function to double?

// Code 2 # include <stdio. h> int main () {int A = 30; double D = 4.4334; printf ("d = % F", call (d); Return 0 ;} double call (double D) {printf ("helloworld \ n"); Return D ;}

GCC indicates that the type of the call function is confusing ~

D:\prj\core_c>gcc demo.c -o demo.outdemo.c:8:8: error: conflicting types for 'call'demo.c:5:16: note: previous implicit declaration of 'call' was here

2. The called function is defined before the main function.

The call method in Code 2 above is before Main, so there will be no problem.

3. Declare the called function before defining all functions.

// Code 4 # include <stdio. h> double call (double D); int main () {int A = 30; double D = 4.4334; printf ("d = % F", call (d )); return 0;} double call (double D) {printf ("helloworld \ n"); Return D ;}

It is equivalent to making an external statement.

 

<2> parameters.

Example:

(1) function declaration, saving the variable name.

Int getmax (int A, int B); // you can save the variable name to facilitate compilation of system errors: int getmax (INT, INT );

(2). You do not need to allocate memory for the shape parameters in macro definition.

#define P(d) printf("%d",d)

Beginner's notes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.