Const Pointer in C
Level 4176 keystrokes
Demonstrates const pointer vs pointer to const data.
C code
// Two integer variables1int a = 10, b = 20;// Pointer to const int: the pointer can change, *ptr1 = ... is an error2const int *ptr1 = &a;// Const pointer to int: the value can change, ptr2 = ... is an error3int *const ptr2 = &a;// Print the value through ptr1 (10)4printf("*ptr1: %d\n", *ptr1);// ptr1 can point to different address5ptr1 = &b;// Now ptr1 points to b6printf("*ptr1: %d\n", *ptr1);// ptr2 can modify the value it points to7*ptr2 = 30;// a is now 308printf("*ptr2: %d\n", *ptr2);Output
*ptr1: 10 *ptr1: 20 *ptr2: 30
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
*× 9;× 8"× 6=× 6,× 4:× 3(× 3)× 3\× 3&× 3