- 函数的返回值:
- 所有函数的返回值都是通过
return关键字
返回的; - 返回一个基本类型的值:
- 案例:
int my_mod(int x,int y){return x % y;}
int *func(int *p){return p;}
int k = 20;
int *func1(){return &k;}
#include<stdio.h>int k = 20;int my_mod(int x,int y){return x % y;}int *func(int *p){return p;}int *func1(){return &k;}
int main(int argc, const char *argv[])
{int mod = my_mod(10,3);printf("mod = %d\n",mod);int b = 88;int *q = func(&b);printf("&b = %p,q = %p,*q = %d\n",&b,q,*q);int *c = func1();printf("*c = %d\n",*c);return 0;
}
mod = 1
&b = 0x7ffd9d1eeda0,q = 0x7ffd9d1eeda0,*q = 88
*c = 20