MCQOPTIONS
Saved Bookmarks
This section includes 27 Mcqs, each offering curated multiple-choice questions to sharpen your C Program knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
char *ptr;char myString[] = "abcdefg";ptr = myString;ptr += 5;what string does ptr point to in the sample code above?~! |
| A. | fg |
| B. | efg |
| C. | defg |
| D. | cdefg |
| E. | bcdefg |
| Answer» B. efg | |
| 2. |
char* myfunc(char *ptr){ ptr+=3; return(ptr);}void main(){ char *x, *y; x = "EXAMVEDA"; y = myfunc(x); printf("y=%s", y);}What will be printed when the sample code above is executed?~! |
| A. | y=EXAMVEDA |
| B. | y=AMVEDA |
| C. | y=MVEDA |
| D. | y=VEDA |
| E. | y=EDA |
| Answer» D. y=VEDA | |
| 3. |
*$_A function 'p' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as? |
| A. | int(*p(char *))[] |
| B. | int *p(char *)[] |
| C. | int (*p) (char *)[] |
| D. | None of these. |
| Answer» B. int *p(char *)[] | |
| 4. |
*/*_What will be the output?main() { char *p; p = "Hello"; printf("%cn",*&*p); }? |
| A. | Hello |
| B. | H |
| C. | Some address will be printed |
| D. | None of these. |
| Answer» C. Some address will be printed | |
| 5. |
%_#includevoid main(){ int *ptr, a=10; ptr = &a; *ptr += 1; printf("%d, %d", *ptr, a);}_% |
| A. | 10, 10 |
| B. | 10, 11 |
| C. | 11, 10 |
| D. | 11, 11 |
| Answer» E. | |
| 6. |
_ Comment on the following pointer declaration?int *ptr, p;$? |
| A. | ptr is a pointer to integer, p is not. |
| B. | ptr and p, both are pointers to integer. |
| C. | ptr is pointer to integer, p may or may not be. |
| D. | ptr and p both are not pointers to integer. |
| Answer» B. ptr and p, both are pointers to integer. | |
| 7. |
_Comment on the following?const int *ptr;$? |
| A. | We cannot change the value pointed by ptr. |
| B. | We cannot change the pointer ptr itself. |
| C. | Both of the above |
| D. | We can change the pointer as well as the value pointed by it. |
| Answer» B. We cannot change the pointer ptr itself. | |
| 8. |
_Choose the best answer.Prior to using a pointer variable$? |
| A. | It should be declared. |
| B. | It should be initialized. |
| C. | It should be both declared and initialized. |
| D. | None of these. |
| Answer» D. None of these. | |
| 9. |
The declarationint (*p) [5];means? |
| A. | p is one dimensional array of size 5, of pointers to integers. |
| B. | p is a pointer to a 5 elements integer array. |
| C. | The same as int *p[ |
| D. | None of these. |
| Answer» C. The same as int *p[ | |
| 10. |
Determine Output:main(){ char *str1 = "abcd"; char str2[] = "abcd"; printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));} |
| A. | 2 5 5 |
| B. | 2 4 4 |
| C. | 8 5 5 |
| D. | 2 4 5 |
| Answer» D. 2 4 5 | |
| 11. |
The operator > and < are meaningful when used with pointers, if |
| A. | The pointers point to data of similar type. |
| B. | The pointers point to structure of similar data type. |
| C. | The pointers point to elements of the same array. |
| D. | None of these. |
| Answer» D. None of these. | |
| 12. |
Determine Output:void main(){ char far *farther, *farthest; printf("%d..%d", sizeof(farther), sizeof(farthest));} |
| A. | 4..2 |
| B. | 2..2 |
| C. | 4..4 |
| D. | 2..4 |
| Answer» B. 2..2 | |
| 13. |
What will be the output of the following program code?#includevoid main(){ int i = 10; void *p = &i; printf("%f", *(float *)p);} |
| A. | Error |
| B. | 10 |
| C. | 0.000000 |
| D. | None of these. |
| Answer» D. None of these. | |
| 14. |
What will be the output of the following program?#includevoid main(){ int i = 10; void *p = &i; printf("%d\n", (int)*p);} |
| A. | Compiler time error |
| B. | Segmentation fault/runtime crash |
| C. | 10 |
| D. | Undefined behavior |
| Answer» B. Segmentation fault/runtime crash | |
| 15. |
The statement int **a; |
| A. | is illegal |
| B. | is legal but meaningless |
| C. | is syntactically and semantically correct |
| D. | None of these. |
| Answer» D. None of these. | |
| 16. |
The address operator &, cannot act on |
| A. | R-values |
| B. | Arithmetic expressions |
| C. | Both of the above |
| D. | Local variables |
| E. | Members of a structure |
| Answer» D. Local variables | |
| 17. |
Determine output:#include void main(){ char *p = NULL; char *q = 0; if(p) printf(" p "); else printf("nullp"); if(q) printf("q"); else printf(" nullq");} |
| A. | p q |
| B. | Depends on the compiler |
| C. | x nullq where x can be p or nullp depending on the value of NULL |
| D. | nullp nullq |
| Answer» E. | |
| 18. |
Find the output of the following program.void main(){ int array[10]; int *i = &array[2], *j = &array[5]; int diff = j-i; printf("%d", diff);} |
| A. | 3 |
| B. | 6 |
| C. | Garbage value |
| D. | Error |
| Answer» B. 6 | |
| 19. |
Find the output of the following program.void main(){ char *msg = "hi"; printf(msg);} |
| A. | hi |
| B. | h |
| C. | hi followed by garbage value |
| D. | Error |
| E. | Garbage Value |
| Answer» B. h | |
| 20. |
Which of the following is the correct way of declaring a float pointer: |
| A. | float ptr; |
| B. | float *ptr; |
| C. | *float ptr; |
| D. | None of the above |
| Answer» C. *float ptr; | |
| 21. |
What will be the output of the following program code?#include void main(){ int i=3, *j, **k; j = &i; k = &j; printf("%d%d%d", *j, **k, *(*k));} |
| A. | 444 |
| B. | 000 |
| C. | 333 |
| D. | 433 |
| E. | Garbage Value |
| Answer» D. 433 | |
| 22. |
What will be printed after compiling and running the following code?main() { char *p; printf("%d %d",sizeof(*p), sizeof(p));} |
| A. | 1 1 |
| B. | 1 2 |
| C. | 2 1 |
| D. | 2 2 |
| Answer» C. 2 1 | |
| 23. |
What would be the output for the following Turbo C code?#includevoid main(){ int a[]={ 1, 2, 3, 4, 5 }, *p; p=a; ++*p; printf("%d ", *p); p += 2; printf("%d", *p);} |
| A. | 2 4 |
| B. | 3 4 |
| C. | 2 2 |
| D. | 2 3 |
| E. | 3 3 |
| Answer» E. 3 3 | |
| 24. |
What is the base data type of a pointer variable by which the memory would be allocated to it? |
| A. | int |
| B. | float |
| C. | No data type |
| D. | Depends upon the type of the variable to which it is pointing. |
| E. | unsigned int |
| Answer» F. | |
| 25. |
Which of the following statements are true after execution of the program.void main(){ int a[10], i, *p; a[0] = 1; a[1] = 2; p = a; (*p)++;} |
| A. | a[1] = 3 |
| B. | a[0] = 2 |
| C. | a[1] = 2 |
| D. | a[0] = 3 |
| E. | Compilation error |
| Answer» C. a[1] = 2 | |
| 26. |
Find the output of the following program.void main(){ int i=10; /* assume address of i is 0x1234ABCD */ int *ip=&i; int **ipp=&&i; printf("%x,%x,%x", &i, ip, *ipp); } |
| A. | 0x1234ABCD, 0x1234ABCD, 10 |
| B. | 0x1234ABCD, 0x1234ABCD, 0x1234ABCD |
| C. | 0x1234ABCD, 10, 10 |
| D. | Syntax error |
| E. | Runtime error |
| Answer» E. Runtime error | |
| 27. |
Find the output of the following program.void main(){ printf("%d, %d", sizeof(int *), sizeof(int **));} |
| A. | 2, 0 |
| B. | 0, 2 |
| C. | 2, 2 |
| D. | 2, 4 |
| E. | 4, 4 |
| Answer» D. 2, 4 | |