constとポインタを組み合わせた3つのケース
1224 ワード
/*
* ppp.c
*
* Created on: 2015 10 29
* Author: xn666
*/
#include
#include
#include
// 、 , ,
void func01(){
int * p = NULL;
int a = 20;
int b = 40;
p = &a;
printf("%p
",p); //
p = &b;
printf("%p
",p); //
*p = 6;
printf("%d
",*p); //
}
// 、 const :
//1.const int *p //
//2.int * const p // ,
//3.const int * const p // ,
void func02(){
int a = 3;
int b = 4;
//1.const int *p
const int *p = &a;
//*p = 5; // ,
printf("const int *p = %d
",*p);
p = &b;
printf("const int *p = %d
",*p);
//2.int * const p
int * const t = &a;
//t = &b; // ,
printf("const int *t = %d
",*t);
*t = 7;
printf("const int *t = %d
",*t);
//3.const int * const p
const int * const s = &a;
//s = &b; // ,
//*s = 8;
printf("const int *s = %d
",*s);
}
int main(){
//func01();
func02();
return 0;
}