MCQOPTIONS
Saved Bookmarks
This section includes 79 Mcqs, each offering curated multiple-choice questions to sharpen your Pointers knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What will be the output of the program ? #include int *check(static int, static int); int main() { int *c; c = check(10, 20); printf("%d n", 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); } |
| A. | 10 |
| B. | 20 |
| C. | Error: Non portable pointer conversion |
| D. | Error: cannot use static for function parameters |
| Answer» E. | |
| 2. |
Which of the following changes can correct the program so that it prints Geeks Quiz ? #include void myStrcat(char *a, char *b) { int m = strlen(a); int n = strlen(b); int i; for (i = 0; i <= n; i++) a[m+i] = b[i]; } int main() { char *str1 = "Geeks "; char *str2 = "Quiz"; myStrcat(str1, str2); printf("%s ", str1); return 0; } |
| A. | char *str1 = Geeks ; can be changed to char str1[100] = Geeks ; |
| B. | char *str1 = Geeks ; can be changed to char str1[100] = Geeks ; and a line a[m+n-1] = 0 is added at the end of myStrcat |
| C. | A line a[m+n-1] = 0 is added at the end of myStrcat |
| D. | A line a = (char *)malloc(sizeof(char)*(strlen(a) + strlen(b) + 1)) is added at the beginning of myStrcat() |
| Answer» B. char *str1 = Geeks ; can be changed to char str1[100] = Geeks ; and a line a[m+n-1] = 0 is added at the end of myStrcat | |
| 3. |
Which of the following declaration throw run-time error? |
| A. | int **c = &c; |
| B. | int **c = &*c; |
| C. | int **c = **c; |
| D. | None of the mentioned |
| Answer» E. | |
| 4. |
Comment on the output of this C code? int main() { int a = 10; int **c -= &&a; } |
| A. | You cannot apply any arithmetic operand to a pointer. |
| B. | We don t have address of an address operator |
| C. | Both (a) and (b) |
| D. | None of the mentioned. |
| Answer» C. Both (a) and (b) | |
| 5. |
What substitution should be made to //-Ref such that ptr1 points to variable C? int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a; int **sptr = &ptr1; //-Ref } |
| A. | *sptr = &c; |
| B. | **sptr = &c; |
| C. | *ptr1 = &c; |
| D. | None of the mentioned. |
| Answer» B. **sptr = &c; | |
| 6. |
What is the output of this C code? int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c; int **sptr = &ptr1; //-Ref *sptr = ptr2; } |
| A. | ptr1 points to a |
| B. | ptr1 points to b |
| C. | sptr points to ptr2 |
| D. | None of the mentioned |
| Answer» C. sptr points to ptr2 | |
| 7. |
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes? #include int main() { int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; printf("%u, %u, %u n", a[0]+1, *(a[0]+1), *(*(a+0)+1)); return 0; } |
| A. | 448, 4, 4 |
| B. | 520, 2, 2 |
| C. | 1006, 2, 2 |
| D. | Error |
| Answer» D. Error | |
| 8. |
What will be the output of the program ? #include int main() { int i=3, *j, k; j = &i; printf("%d n", i**j*i+*j); return 0; } |
| A. | 30 |
| B. | 37 |
| C. | 7 |
| D. | 9 |
| Answer» B. 37 | |
| 9. |
What will be the output of the program ? #include int main() { static char *s[] = {"black", "white", "pink", "violet"}; char **ptr[] = {s+3, s+2, s+1, s}, ***p; p = ptr; ++p; printf("%s", **p+1); return 0; } |
| A. | ink |
| B. | ack |
| C. | ite |
| D. | let |
| Answer» B. ack | |
| 10. |
What will be the output of the program? #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 n", *p, *q); return 0; } |
| A. | 8, 10 |
| B. | 10, 2 |
| C. | 8, 1 |
| D. | Garbage values |
| Answer» B. 10, 2 | |
| 11. |
What will be the output of the program ? #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; } |
| A. | JCK |
| B. | J65K |
| C. | JAK |
| D. | JACK |
| Answer» E. | |
| 12. |
What will be the output of the program if the size of pointer is 4-bytes? #include int main() { printf("%d, %d n", sizeof(NULL), sizeof("")); return 0; } |
| A. | 2, 1 |
| B. | 2, 2 |
| C. | 4, 1 |
| D. | 4, 2 |
| Answer» D. 4, 2 | |
| 13. |
What will be the output of the program ? #include int main() { char *str; str = "%s"; printf(str, "K n"); return 0; } |
| A. | Error |
| B. | No output |
| C. | K |
| D. | %s |
| Answer» D. %s | |
| 14. |
What would be the equivalent pointer expression for referring the array element a[i][j][k][l] |
| A. | ((((a+i)+j)+k)+l) |
| B. | *(*(*(*(a+i)+j)+k)+l) |
| C. | (((a+i)+j)+k+l) |
| D. | ((a+i)+j+k+l) |
| Answer» C. (((a+i)+j)+k+l) | |
| 15. |
How many bytes are occupied by near, far and huge pointers (DOS)? |
| A. | near=2 far=4 huge=4 |
| B. | near=4 far=8 huge=8 |
| C. | near=2 far=4 huge=8 |
| D. | near=4 far=4 huge=8 |
| Answer» B. near=4 far=8 huge=8 | |
| 16. |
What will be the output of the program ? #include int main() { char str[20] = "Hello"; char *const p=str; *p='M'; printf("%s n", str); return 0; } |
| A. | Mello |
| B. | Hello |
| C. | HMello |
| D. | MHello |
| Answer» B. Hello | |
| 17. |
Can you combine the following two statements into one? char *p; p = (char*) malloc(100); |
| A. | char p = *malloc(100); |
| B. | char *p = (char) malloc(100); |
| C. | char *p = (char*)malloc(100); |
| D. | char *p = (char *)(malloc*)(100); |
| Answer» D. char *p = (char *)(malloc*)(100); | |
| 18. |
What will be the output of the program ? #include int main() { int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%d, z=%d n", x, y, z); return 0; } |
| A. | x=31, y=502, z=502 |
| B. | x=31, y=500, z=500 |
| C. | x=31, y=498, z=498 |
| D. | x=31, y=504, z=504 |
| Answer» E. | |
| 19. |
What will be the output of the program If the integer is 4bytes long? #include int main() { int ***r, **q, *p, i=8; p = &i; q = &p; r = &q; printf("%d, %d, %d n", *p, **q, ***r); return 0; } |
| A. | 8, 8, 8 |
| B. | 4000, 4002, 4004 |
| C. | 4000, 4004, 4008 |
| D. | 4000, 4008, 4016 |
| Answer» B. 4000, 4002, 4004 | |
| 20. |
What will be the output of the program ? #include void fun(void *p); int i; int main() { void *vptr; vptr = &i; fun(vptr); return 0; } void fun(void *p) { int **q; q = (int**)&p; printf("%d n", **q); } |
| A. | Error: cannot convert from void** to int** |
| B. | Garbage value |
| C. | No output |
| Answer» A. Error: cannot convert from void** to int** | |
| 21. |
How many number of pointer (*) does C have against a pointer variable declaration? |
| A. | 7 |
| B. | 127 |
| C. | 255 |
| D. | No limits |
| Answer» E. | |
| 22. |
Which of the following is the correct syntax to send an array as a parameter to function? |
| A. | func(&array); |
| B. | func(#array); |
| C. | func(*array); |
| D. | func(array[size]); |
| Answer» B. func(#array); | |
| 23. |
What will be the output of the following C code? #include int main() { int i = 10; int *p = &i; foo(&p); printf("%d ", *p); printf("%d ", *p); } void foo(int **const p) { int j = 11; *p = &j; printf("%d ", **p); } |
| A. | 11 11 11 |
| B. | 11 11 Undefined-value |
| C. | Compile time error |
| D. | Segmentation fault/code-crash |
| Answer» C. Compile time error | |
| 24. |
What will be the output of the following C code? #include int main() { int i = 10; int *const p = &i; foo(&p); printf("%d n", *p); } void foo(int **p) { int j = 11; *p = &j; printf("%d n", **p); } |
| A. | 11 11 |
| B. | Undefined behaviour |
| C. | Compile time error |
| D. | Segmentation fault/code-crash |
| Answer» B. Undefined behaviour | |
| 25. |
What will be the output of the following C code? #include int main() { int i = 11; int *p = &i; foo(&p); printf("%d ", *p); } void foo(int *const *p) { int j = 10; *p = &j; printf("%d ", **p); } |
| A. | Compile time error |
| B. | 10 10 |
| C. | Undefined behaviour |
| D. | 10 11 |
| Answer» B. 10 10 | |
| 26. |
What will be the output of the following C code? #include int main() { int i = 97, *p = &i; foo(&p); printf("%d ", *p); return 0; } void foo(int **p) { int j = 2; *p = &j; printf("%d ", **p); } |
| A. | 2 2 |
| B. | 2 97 |
| C. | Undefined behaviour |
| D. | Segmentation fault/code crash |
| Answer» B. 2 97 | |
| 27. |
What will be the output of the following C code? #include int main() { int i = 97, *p = &i; foo(&i); printf("%d ", *p); } void foo(int *p) { int j = 2; p = &j; printf("%d ", *p); } |
| A. | 2 97 |
| B. | 2 2 |
| C. | Compile time error |
| D. | Segmentation fault/code crash |
| Answer» B. 2 2 | |
| 28. |
What will be the output of the following C code? #include void foo(int*); int main() { int i = 10, *p = &i; foo(p++); } void foo(int *p) { printf("%d n", *p); } |
| A. | 10 |
| B. | Some garbage value |
| C. | Compile time error |
| D. | Segmentation fault |
| Answer» B. Some garbage value | |
| 29. |
What is the output of this C code? void foo(int*); int main() { int i = 10; foo((&i)++); } void foo(int *p) { printf("%d n", *p); } |
| A. | 10 |
| B. | Some garbage value |
| C. | Compile time error |
| D. | Segmentation fault/code crash |
| Answer» D. Segmentation fault/code crash | |
| 30. |
What will be the output of the following C code? #include void foo(int*); int main() { int i = 10; foo((&i)++); } void foo(int *p) { printf("%d n", *p); } |
| A. | 10 |
| B. | Some garbage value |
| C. | Compile time error |
| D. | Segmentation fault/code crash |
| Answer» D. Segmentation fault/code crash | |
| 31. |
What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%d n", *ptr); } |
| A. | Address of x |
| B. | Junk value |
| C. | Run time error |
| Answer» A. Address of x | |
| 32. |
What is the output of this C code? void main() { int x = 0; int *ptr = &5; printf("%p n", ptr); } |
| A. | 5 |
| B. | Address of 5 |
| C. | Nothing |
| D. | Compile time error |
| Answer» E. | |
| 33. |
What will be the output of the program ? #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(" n", x); return 0; } |
| A. | Alice |
| B. | ecilA |
| C. | Alice lice ice ce e |
| D. | lice ice ce e |
| Answer» E. | |
| 34. |
If the size of integer is 4bytes, What will be the output of the program? #include int main() { int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d n", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0; } |
| A. | 10, 2, 4 |
| B. | 20, 4, 4 |
| C. | 16, 2, 2 |
| D. | 20, 2, 2 |
| Answer» C. 16, 2, 2 | |
| 35. |
What is the output of this C code? void main() { int x = 0; int *ptr = &x; printf("%p n", ptr); ptr++; printf("%p n ", ptr); } |
| A. | 0xbfd605e8 0xbfd605ec |
| B. | 0xbfd605e8 0cbfd60520 |
| C. | 0xbfd605e8 0xbfd605e9 |
| D. | Run time error |
| Answer» B. 0xbfd605e8 0cbfd60520 | |
| 36. |
What is the output of this C code? int x = 0; void main() { int *const ptr = &x; printf("%p n", ptr); ptr++; printf("%p n ", ptr); } |
| A. | 0 1 |
| B. | Compile time error |
| C. | 0xbfd605e8 0xbfd605ec |
| D. | 0xbfd605e8 0xbfd605e8 |
| Answer» C. 0xbfd605e8 0xbfd605ec | |
| 37. |
What will be the output of the program ? #include power(int**); int main() { int a=5, *aa; /* Address of 'a' is 1000 */ aa = &a; a = power(&aa); printf("%d n", a); return 0; } power(int **ptr) { int b; b = **ptr***ptr; return (b); } |
| A. | 5 |
| B. | 25 |
| C. | |
| D. | D. |
| Answer» C. | |
| 38. |
What will be the output of the program ? #include int main() { char str1[] = "India"; char str2[] = "BIX"; char *s1 = str1, *s2=str2; while(*s1++ = *s2++) printf("%s", str1); printf(" n"); return 0; } |
| A. | IndiaBIX |
| B. | BndiaBIdiaBIXia |
| C. | India |
| D. | (null) |
| Answer» C. India | |
| 39. |
What will be the output of the program assuming that the array begins at location 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 n", a, *a, **a, ***a); return 0; } |
| A. | 1002, 2004, 4008, 2 |
| B. | 2004, 4008, 8016, 1 |
| C. | 1002, 1002, 1002, 1 |
| D. | Error |
| Answer» D. Error | |
| 40. |
What will be the output of the program ? #include int main() { char str[] = "peace"; char *s = str; printf("%s n", s++ +3); return 0; } |
| A. | peace |
| B. | eace |
| C. | ace |
| D. | ce |
| Answer» E. | |
| 41. |
What will be the output of the program ? #include int main() { char *p; p="hello"; printf("%s n", *&*&p); return 0; } |
| A. | llo |
| B. | hello |
| C. | ello |
| D. | h |
| Answer» C. ello | |
| 42. |
What will be the output of the program ? #include int main() { char *str; str = "%d n"; str++; str++; printf(str-2, 300); return 0; } |
| A. | No output |
| B. | 30 |
| C. | 3 |
| D. | 300 |
| Answer» E. | |
| 43. |
What will be the output of the program ? #include int main() { printf("%c n", 7["IndiaBIX"]); return 0; } |
| A. | Error: in printf |
| B. | Nothing will print |
| C. | print "X" of IndiaBIX |
| D. | print "7" |
| Answer» D. print "7" | |
| 44. |
What will be the output of the program? #include int main() { int arr[3] = {2, 3, 4}; char *p; p = arr; p = (char*)((int*)(p)); printf("%d, ", *p); p = (int*)(p+1); printf("%d", *p); return 0; } |
| A. | 2, 3 |
| B. | 2, 0 |
| C. | 2, Garbage value |
| D. | 0, 0 |
| Answer» C. 2, Garbage value | |
| 45. |
What is the output of this C code? int x = 0; void main() { int *ptr = &x; printf("%p n", ptr); x++; printf("%p n ", ptr); } |
| A. | Same address |
| B. | Different address |
| C. | Compile time error |
| D. | Varies |
| Answer» B. Different address | |
| 46. |
Are the three declarations char **apple, char *apple[ ], and char apple[ ][ ] same? |
| A. | True |
| B. | False |
| Answer» C. | |
| 47. |
What is the output of this C code? int *f(); int main() { int *p = f(); printf("%d n", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; } |
| A. | 10 |
| B. | Compile time error |
| C. | Segmentation fault/runtime crash since pointer to local variable is returned |
| D. | Undefined behaviour |
| Answer» B. Compile time error | |
| 48. |
What is the output of this C code? int *f(); int main() { int *p = f(); printf("%d n", *p); } int *f() { int j = 10; return &j; } |
| A. | 10 |
| B. | Compile time error |
| C. | Segmentation fault/runtime crash |
| D. | Undefined behaviour |
| Answer» B. Compile time error | |
| 49. |
What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%f n", *(float*)p); return 0; } |
| A. | Compile time error |
| B. | Undefined behaviour |
| C. | 10 |
| D. | 0.000000 |
| Answer» E. | |
| 50. |
What is the output of this C code? int main() { int i = 10; void *p = &i; printf("%d n", (int)*p); return 0; } |
| A. | Compile time error |
| B. | Segmentation fault/runtime crash |
| C. | 10 |
| D. | Undefined behaviour |
| Answer» B. Segmentation fault/runtime crash | |