Programmer --- C language details 27 (when the function has no parameters, the function returns the int type proof by default, the return value by default, and the void pointer ++ Operation)

Source: Internet
Author: User

Programmer --- C language details 27 (when the function has no parameters, the function returns the int type proof by default, the return value by default, and the void pointer ++ Operation)
Main Content: details when the function has no parameters, proof of int type returned by the function by default, return value by default, void pointer ++ operation

I. Details of functions without Parameters

Void should be added when the function has no Parameter

A function in C Language

Void f ();

Pass the parameter f (2) in use; no error is reported, but an error is reported in c ++.

It is best to add void to specify that the function has no parameters.

2. The default return type of the function is int.

See the following program

3. return returns 1 by default.

Details: return cannot return the pointer in the execution stack memory because the function body is automatically destroyed when it ends.

Iv. void pointer ++ operation

Void * p;

P ++; // errors in ANSI compilation. In the GNU Compiler, p ++ is consistent with char *.

# Include

 
  
A () {return 3; // return; // write this form directly. By default, return 1} B (int a, int B) {return a + B ;} int main () {printf ("func a return = % d \ n", a (2); // if the function has no parameters, it should be declared as void, if the parameter is not declared in c and no error is reported, an error is reported in C ++, if the function has no parameter, it is declared as void printf ("func B retunr = % d \ n", B (,); // The function has no return type, the int-type printf ("------------------------- \ n"); void * p; p ++; // compiled by using the gcc and mingw5 compilers (GNU ), they think that p ++ is of the char * type and use VC6.0 to compile the error (that is, ANSI) return 0 ;}

 
Output:



Related Article

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.