Govt Exams
int x = 50;
int *p = &x;
int *q = p;
q = NULL;
printf("%d", *p);
Setting q to NULL doesn't affect p. p still points to x, so *p is 50.
void pointers are generic pointers that must be cast to appropriate type before dereferencing.
int *p = (int*)malloc(sizeof(int));
*p = 5;
free(p);
p = NULL;
This is proper memory management: allocate, use, free, and nullify to prevent dangling pointer.
Due to operator precedence, *p++ is equivalent to *(p++), incrementing the pointer. (*p)++ explicitly increments the value.
strspn(str, charset) returns length of initial segment of str containing only characters from charset. Useful for token parsing.
strcpy() assumes null-terminated strings. memcpy() copies exact number of bytes, suitable for binary data or embedded nulls.
Parentheses change precedence. int (*ptr)[5] is pointer to array of 5 ints. int *arr[5] is array of 5 pointers.
gets() has no buffer overflow protection and was removed in C11. fgets(str, size, stdin) is the safer alternative with size limiting.
In row-major order: address = base + (i*m*n + j*n + k) where m=3, n=4. So arr[1][2][3] = base + 1*12 + 2*4 + 3 = base + 23.
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault at runtime.