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
In C, precedence of unary * and multiplication: evaluate this expression. #include
int main() { int i = 3, j, k; j = &i; printf("%d ", i**ji + *j); return 0; }
In C, using a[b] == (a+b) symmetry: what character is printed? #include
int main() { printf("%c ", 7["CuriousTab"]); return 0; }
In C programming, what will be the output of the following code? Carefully consider pointer arithmetic on a string and the postfix increment. #include
int main() { char str[] = "peace"; char s = str; printf("%s ", s++ + 3); return 0; }
In C (assume pointer size = 4 bytes), what will this program print for the sizes of NULL and an empty string literal? #include
int main() { printf("%d, %d ", sizeof(NULL), sizeof("")); return 0; }
In C, what is the output of the following pointer-to-pointer calculation? Pay attention to operator precedence and tokenization. #include
int power(int ); int main() { int a = 5, aa; / Suppose &a is 1000 (illustrative only) / aa = &a; a = power(&aa); printf("%d ", a); return 0; } int power(int **ptr) { int b; b = ptrptr; / parsed as (**ptr) * (**ptr) / return b; }
In C, consider this function that modifies an array through a pointer. What is printed after the loop and why? #include
void change(int b, int n) { int i; for (i = 0; i < n; i++) (b + 1) = (b + i) + 5; / note the constant +1 on the left / } int main() { int i, a[] = {2, 4, 6, 8, 10}; change(a, 5); for (i = 0; i <= 4; i++) printf("%d, ", a[i]); return 0; }
In C, given a 3D array and two pointers, what values are printed? Understand row-major layout and element addresses. #include
int main() { int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8}; int *p, q; p = &arr[1][1][1]; q = (int)arr; printf("%d, %d ", *p, q); return 0; }
In C, a const pointer to char is used to modify a string buffer. What gets printed after changing the first character? #include
int main() { char str[20] = "Hello"; char const p = str; / const pointer, modifiable characters */ *p = 'M'; printf("%s ", str); return 0; }
In C, arrays of pointers and multi-level pointers: what substring is printed by this code? #include
int main() { static char *s[] = {"black", "white", "pink", "violet"}; char *ptr[] = {s + 3, s + 2, s + 1, s}, p; p = ptr; ++p; / now points to (s + 2) / printf("%s", p + 1); return 0; }
In C, identify the correct diagnostic for using the keyword static on function parameters and the result of returning their addresses. #include
int *check(static int, static int); int main() { int *c; c = check(10, 20); printf("%d ", c); return 0; } int *check(static int i, static int j) { int *p, *q; p = &i; q = &j; if (i >= 45) return p; else return q; }
In C, using void* to reference different types: what does this program print when casting to the correct types before dereferencing? #include
int main() { void vp; char ch = 74, cp = "JACK"; int j = 65; vp = &ch; printf("%c", (char)vp); vp = &j; printf("%c", (int)vp); vp = cp; printf("%s", (char)vp + 2); return 0; }
In C, modify the recursive factorial function so that the computed factorial is stored back through the pointer argument. Which statement should be added where indicated? #include
void fact(int*); int main() { int i = 5; fact(&i); printf("%d ", i); return 0; } void fact(int *j) { static int s = 1; if (*j != 0) { s = s * *j; *j = j - 1; fact(j); / Add a statement here */ } }
In C on a typical PC, consider aliasing a float as bytes and printing the first byte's numeric value. What does this program output? #include
int main() { float a = 3.14; char j; j = (char)&a; // alias the float's storage as bytes printf("%d ", *j); // print the first byte as an integer return 0; }
In C, analyze multi-dimensional array initialization and deep dereferencing. What does this print? #include
int main() { int arr[3][3] = {1, 2, 3, 4}; printf("%d ", (((arr)))); return 0; }
C strings copy loop: which statement must be added to properly terminate the destination so that it prints "CuriousTab"? #include
int main() { char s[] = "CuriousTab"; char t[25]; char *ps, *pt; ps = s; pt = t; while (*ps) *pt++ = *ps++; /* Add a statement here */ printf("%s ", t); return 0; }
Pointers to pointers: add one statement inside fun so that j in main receives the address of local a (demonstration of double-pointer assignment). #include
int main() { int j; void fun(int*); fun(&j); return 0; } void fun(int *k) { int a = 10; / Add a statement here */ }
Function declaration syntax: choose the correct prototype for a function that takes float*** and returns float****.
Pointer declaration meaning: what does the declaration "char k;" represent in C?
Pointer basics: what do the variables represent here, and which statement is correct? #include
int main() { int i = 10; int *j = &i; return 0; }
1
2