Programming/C
const int* const pointer
halatha
2011. 5. 7. 06:33
// http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/C/Documents/Tip#s-2
#include <stdio.h>
void main()
{
const int i = 3;
//i = 4; // compile error
int* p = (int*)&i;
printf("%d\t%d\n", i, *p);
*p = 4;
printf("%d\t%d\n", i, *p);
const int ci1 = 4, ci2 = 8;
// canNOT change value, can change the address
const int* cip = &ci1;
printf("%d\t%d\t%d\n", ci1, ci2, *cip);
cip = &ci2;
//*cip = 0; // compile error
printf("%d\t%d\t%d\n", ci1, ci2, *cip);
int i1 = 4, i2 = 8;
// can change value, canNOT change the address
int* const ipc = &i1;
printf("%d\t%d\t%d\n", i1, i2, *ipc);
//ipc = &i2; // compile error
*ipc = 0;
printf("%d\t%d\t%d\n", i1, i2, *ipc);
const int ci3 = 3, ci4 = 4;
const int* const cipc = &ci1;
//cipc = &ci2;
//*cipc = 0;
printf("%d\t%d\t%d\n", ci3, ci4, *cipc);
}