Learning point C language (33): function-passing values and passing addresses and shapes to participate in real parameters

Source: Internet
Author: User
1. Pass value parameters (non-pointer parameters ):
 
# Include <stdio. h> int Inc (int x); int main (void) {int num = 1; printf ("% d \ n", Inc (Num )); /* 2 */printf ("% d \ n", num);/* 1; num does not change. When used as a function parameter, it only copies the past */getchar (); return 0;} int Inc (int x) {x ++; return X ;}

  

2. Address Transfer: the parameter is a pointer and the parameter is an address

 
# Include <stdio. h> int Inc (int * P); int main (void) {int num = 1; printf ("% d \ n", Inc (& num )); /* 2 */printf ("% d \ n", num);/* 2; num modified */getchar (); Return 0 ;} int Inc (int * P) {* P = * p + 1;/* changed the value through the address */return * P ;}

  

3. Example of transferring an address but not modifying it:

# Include <stdio. h> int Inc (int * P); int main (void) {int num = 1; printf ("% d \ n", Inc (& num )); /* 2 */printf ("% d \ n", num);/* 1 * // although the function is a transfer address, the num here has not changed; because the following function does not assign a value to the pointer */getchar (); Return 0;} int Inc (int * P) {return * p + 1 ;}

  

4. participate in real parameters:

This is just a title that does not make much sense. For example, in the following example
X and Y are the form parameters of the sum function;
I and 22 are the real parameters of the sum function.
 
# Include <stdio. h> int sum (int x, int y); int main (void) {int I = 11; I = sum (I, 22 ); printf ("% d \ n", I); getchar (); Return 0 ;}int sum (INT X, int y) {return X + Y ;}

  

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.