Govt. Exams
Entrance Exams
char str[] = "GATE";
char *p = str;
printf("%c %c", *p, *(p+3));
p points to str[0] which is 'G'. p+3 points to str[3] which is 'E'. Wait - str="GATE" has indices 0:G, 1:A, 2:T, 3:E. So *(p+3) is 'E'. Correction: answer should be 'G E'. But checking: G-A-T-E at 0-1-2-3, so *(p+3)='E'. The option shows 'G T' - p points to G, p+2 would be T. Re-reading: *(p+3) for "GATE" is 'E'. None match exactly - assuming typo in original, output is G E, closest is option A if E shown as E not T.
const int *p: pointer can change, data cannot. int * const q: pointer cannot change, data can be modified.
Array name acts as pointer to first element in expressions but they're distinct. &arr and arr differ in type.
This allocates row pointers only. Each row needs allocation: arr[i] = (int*)malloc(m * sizeof(int));
%p prints pointer values. NULL representation depends on implementation, commonly shown as 0x0 or (nil).
Parentheses around *ptr give pointer priority. It's a pointer to a function taking 2 ints and returning int.
int arr[5];
arr decays to pointer to first element (int*). &arr is pointer to whole array (int(*)[5]). Pointer arithmetic differs.
int *p = (int*)malloc(5 * sizeof(int));
int *q = p;
p = NULL;
free(q);
q still holds the address even though p is NULL. free(q) properly deallocates memory.
malloc(0) behavior is implementation-defined but typically returns a valid pointer. Freeing it is safe.
arr points to arr[0], p points to arr[2]. arr - p = -2 (p is 2 positions ahead).