Entrance Exams
Govt. 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.
When &y is passed to a function expecting a pointer parameter, the address is passed. Changes via pointer dereference affect the original variable.
The parentheses around *ptr indicate ptr is a pointer. It points to a function that takes two int parameters and returns an int.
int arr[5] = {1,2,3,4,5};
int *p = arr;
p += 2;
printf("%d", *p);
p points to arr[0]. After p += 2, p points to arr[2] which contains value 3. Pointer arithmetic moves by element size.
Comparing pointers with NULL is valid. Comparing unrelated pointers or subtracting pointers from different arrays is undefined behavior.
int *p;
*p = 10;
p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.
After allocating memory for pointers, each pointer (row) must be allocated memory individually in a loop before accessing arr[i][j].
Which statement is TRUE?
const int *p means p can change but the data it points to cannot. int * const q means q cannot change but the data it points to can be modified.
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
q is a pointer to pointer p. **q dereferences q twice: first to get p, then to get the value of x which is 10.
const int *p: pointer can change, data cannot. int * const q: pointer cannot change, data can be modified.