指针复习
/*
============================================================================
Name : Hello.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
void reset(int i);
void reset2(int* p);
void add_by_point(int x,int y,int *result);
int main(void) {
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(int));
int a = 10;
int *p1 = &a;
char *p2 = p1;
printf("%d\n",p1);
printf("%d\n",p2);
printf("%d\n",*p1);//10
printf("%d\n",*p2);
puts("----------------------");
int c[10] = {
1,2,3,4,5
};
//数组内容值默认为0
printf("%d\n",c[5]);
//数组名也是数字首地址
printf("%d\n",c);
//指针运算要根据指针的类型
printf("%d\n",c+1);
//
printf("%d\n",*(c+2));
*(c+2) = 0;
printf("%d\n",*(c+2));
puts("----------------------");
int d = 10;
reset(d);
//函数独立性
printf("%d\n",d);
reset2(&d);
//使用指针的方式突破函数壁垒
printf("%d\n",d);
//什么是返回值
int e = add(3,5);
printf("e = %d\n",e);
int result = 0;
//指针的方式计算结果
add_by_point(3,5,&result);
printf("result = %d\n",result);
}
void reset(int i){
i = 0;
}
void reset2(int* p){
*p = 0;
}
int add(int i,int j ){
/*
* 变量的生命周期
*
* */
int q = i+j;
return q;
}
void add_by_point(int x,int y,int *result){
int r = (x + y);
*result = r;
}