Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Pointers Questions
Pointers and dereferencing in C: which operator retrieves the value stored at the memory address contained in a pointer variable?
C standard macros: in which standard header(s) is the macro NULL guaranteed to be defined?
In C pointer terminology, what does the expression (void*)0 represent?
Accessing structure members through a pointer in C: which operator should be used to reach a field of a struct via a pointer variable?
In C/C++, can the two statements 'char p;' and 'p = (char) malloc(100);' be combined into a single declaration-and-initialization statement? Select the correctly formed combined statement.
In C programming, what is a pointer most accurately described as (choose the best definition in the context of variables and memory addresses)?
In 16-bit DOS memory models, how many bytes are used by near, far, and huge pointers respectively?
For a four-dimensional array a[i][j][k][l] in C, which equivalent pointer expression correctly refers to that element using pointer arithmetic and dereferencing?
C format strings, pointer arithmetic, and printf: what does this program print? #include
int main() { char *str; str = "%d "; str++; str++; printf(str-2, 300); return 0; }
C printf with a string format specifier: what is printed? #include
int main() { char str; str = "%s"; printf(str, "K "); return 0; }
Pointer-based string copy with printing at each step (assume enough destination space): what final string does str1 hold after the loop? #include
int main() { char str1[20] = "India"; // assume sufficient space to avoid overflow char str2[] = "CURIOUSTAB"; char *s1 = str1, *s2 = str2; while (*s1++ = *s2++) printf("%s", str1); printf(" "); return 0; } (We focus on the final content stored in str1 after copying completes.)
Pointer arithmetic and 2D arrays in C (row-major layout): assuming the base address of a begins at 1002 and sizeof(int) = 4 bytes, what does the following print? #include
int main() { int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; printf("%u, %u, %u ", a[0]+1, (a[0]+1), ((a+0)+1)); return 0; }
In C (pointer decay with multidimensional arrays), what will this print if the array 'a' begins at address 1002? #include
int main() { int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2}, {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} }; printf("%u, %u, %u, %d ", a, *a, **a, ***a); return 0; }
In C strings and pointers, what does this print (note: writing to a string literal is undefined; assume it succeeds for this exercise)? #include
#include
int main() { int i, n; char *x = "Alice"; n = strlen(x); *x = x[n]; for (i = 0; i <= n; i++) { printf("%s ", x); x++; } printf(" "); return 0; }
In C (pointers to pointers), given 4-byte int, what does this print? #include
int main() { int ***r, **q, *p, i = 8; p = &i; q = &p; r = &q; printf("%d, %d, %d ", *p, **q, ***r); return 0; }
In C pointer arithmetic with post-increment on pointers, assume &x = 500 and sizeof(int) = 4 bytes. What prints? #include
int main() { int x = 30, *y, z; y = &x; / &x is 500 */ z = y; *y++ = *z++; x++; printf("x=%d, y=%d, z=%d ", x, y, z); return 0; }
In C, casting addresses through void* inside a function: what is printed? #include
void fun(void *p); int i; int main() { void vptr; vptr = &i; / global i zero-initialized / fun(vptr); return 0; } void fun(void p) { int q; q = (int)&p; printf("%d ", q); }
In C, mixing char* and int* and unaligned reads: what prints? #include
int main() { int arr[3] = {2, 3, 4}; char p; p = (char)arr; p = (char*)((int*)(p)); printf("%d, ", p); p = (int)(p + 1); printf("%d", p); return 0; }
In C, using sizeof with arrays and elements (int is 4 bytes): what is printed? #include
int main() { int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d ", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0; }
In C, address-of and dereference cancellation with a char pointer: what is printed? #include
int main() { char p; p = "hello"; printf("%s ", &&p); return 0; }
1
2