const pointer vs. pointer to const
Bookmark on:
/*
ex. usage of a constant pointer to a (variable integer)
ex. how to fuck a pointer to a constant variable
*/
#include
int main(void)
{
const int c=0;
// constant pointer to a (variable) integer: can change the value of the var but not the pointer
int* const ptr1 = malloc(sizeof(int));
*ptr1 = 10;
*ptr1 = 100;
int t;
// pointer to a constant integer: can change the pointer but not the variable
const int* ptr2 = malloc (sizeof(int));
int modvar = 10;
ptr2 = &modvar;
modvar = 100;
printf(”%d\n”, *ptr2);
return 0;
}
About this entry
You’re currently reading “const pointer vs. pointer to const,” an entry on Francesco Gadaleta
- Published:
- 27.06.08 / 10pm
- Category:
- Computer Science
Comments are closed
Comments are currently closed on this entry.