MCQOPTIONS
Saved Bookmarks
This section includes 45 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
In the following code snippet can we declare a new named even though has not been completely declared while using ? |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 2. |
Point out the error in the following code? |
| A. | Error: in *NODEPTR |
| B. | Error: |
| C. | cannot be used until it is defined |
| D. | No error |
| E. | None of above |
| Answer» C. cannot be used until it is defined | |
| 3. |
Is the following declaration acceptable? |
| A. | Yes |
| B. | NO |
| Answer» B. NO | |
| 4. |
Is there any difference in the and in the following code? |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 5. |
Are the properties of and in the following program same? |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 6. |
's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas 's always have a global effect. |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 7. |
In the following code, the is Integer Pointer or Integer? |
| A. | Integer |
| B. | Integer pointer |
| C. | Error in declaration |
| D. | None of above |
| Answer» C. Error in declaration | |
| 8. |
In the following code what is 'P'? |
| A. | P is a constant |
| B. | P is a character constant |
| C. | P is character type |
| D. | None of above |
| Answer» B. P is a character constant | |
| 9. |
What is x in the following program? |
| A. | x is a pointer |
| B. | x is an array of three pointer |
| C. | x is an array of three function pointers |
| D. | Error in x declaration |
| Answer» D. Error in x declaration | |
| 10. |
What will be the output of the following C code?#include <stdio.h> typedef struct MM { int n1, n2; }mm; int main() { struct MM m = {22, 44}; mm k = m; printf("%d n", k.n1); } |
| A. | Compilation Error |
| B. | 44 |
| C. | 22 |
| D. | Garbage value |
| E. | None of these |
| Answer» D. Garbage value | |
| 11. |
Which option should be selected to work the following C expression?string s = "WELCOME"; |
| A. | Such expression cannot be generated in C |
| B. | typedef char [] string; |
| C. | typedef char *string; |
| D. | typedef char [] string; and typedef char *string; |
| E. | None of these |
| Answer» D. typedef char [] string; and typedef char *string; | |
| 12. |
What will be the output of the following C code?#include <stdio.h> typedef struct NN { int n, m; }s = {11, 22}; int main() { NN nn = s; printf("%d n", nn.n); } |
| A. | Depends on the standard |
| B. | 11 |
| C. | 22 |
| D. | Garbage value |
| E. | Compilation Error |
| Answer» F. | |
| 13. |
Which of the following will be the correct output for the program given below ? #include<stdio.h>int main ( ) { typedef int arr[ 5 ]; arr new_arr = {1, 2, 3, 4, 5 }; int k ; for (k = 0; k < 4 ; k++) printf("%d", new_arr[k] ); printf(" n"); return 0;} |
| A. | 1 2 3 4 |
| B. | 1 2 3 4 5 |
| C. | No output |
| D. | Error: Cannot use typedef with an array |
| Answer» B. 1 2 3 4 5 | |
| 14. |
What will be the output of the following C code?#include <stdio.h> typedef struct B { int n1, n2; }; int main() { B k = {10, 20}; printf("%d n", k.n1); } |
| A. | 10 |
| B. | 20 |
| C. | Compilation Error |
| D. | Undefined behaviour |
| E. | None of these |
| Answer» D. Undefined behaviour | |
| 15. |
What will be the output of the following C code?#include <stdio.h> int (*(a()))[2]; typedef int (*(*p)())[2] ptrfun; int main() { ptrfun p1; p1 = a; p1(); return 0; } int (*(a()))[2] { int (*array)[2] = malloc(sizeof*array); return &array; } |
| A. | Nothing |
| B. | Undefined behaviour |
| C. | Compilation Error |
| D. | Garbage value |
| E. | None of these |
| Answer» D. Garbage value | |
| 16. |
What will be the output of the following C code?#include <stdio.h> typedef int integer; int main() { int n1 = 120, *p; float n2 = 250; integer k = n1; p = &k; printf("%d n", *p); return 0; } |
| A. | 250 |
| B. | Compilation Error |
| C. | Garbage value |
| D. | 120 |
| E. | None of these |
| Answer» E. None of these | |
| 17. |
What will be the output of the following C code?#include <stdio.h> typedef struct Employee { char *ch; }Employ; void main() { struct Employee emp; emp.ch = "Welcome"; printf("%s", emp.ch); } |
| A. | Welcome |
| B. | Compilation Error |
| C. | Garbage value |
| D. | Undefined behaviour |
| E. | None of these |
| Answer» B. Compilation Error | |
| 18. |
Which of the given option is the correct method for initialization?typedef char *string; |
| A. | Not more than one space should be given when using typedef |
| B. | *string *q = Welcome ; |
| C. | string p = Welcome ; |
| D. | *string p = B ; |
| E. | None of these |
| Answer» D. *string p = B ; | |
| 19. |
What will be the output of the following C code?#include <stdio.h> typedef struct Employee { char *ch; }Employ; void main() { struct Employ emp; emp.ch = "hello"; printf("%s", emp.ch); } |
| A. | Compilation Error |
| B. | Garbage value |
| C. | hello |
| D. | Undefined behaviour |
| E. | None of these |
| Answer» B. Garbage value | |
| 20. |
What will be the output of the following C code?#include <stdio.h> typedef struct Employee { char *ch; }Employ; void main() { Employ emp; emp.ch = "Hello"; printf("%s", emp.ch); }emp |
| A. | Hello |
| B. | Garbage value |
| C. | Compilation Error |
| D. | All of above |
| E. | None of these |
| Answer» D. All of above | |
| 21. |
In the following code, the P2 is Integer Pointer or Integer?_x000D_ typedef int *ptr;_x000D_ ptr p1, p2; |
| A. | Integer |
| B. | Integer pointer |
| C. | Error in declaration |
| D. | None of above |
| Answer» C. Error in declaration | |
| 22. |
What will be the output of the program?_x000D_ #include_x000D_ _x000D_ typedef struct error {int warning, err, exception;} ERROR;_x000D_ int main()_x000D_ {_x000D_ ERROR e;_x000D_ e.err=1;_x000D_ printf("%d\n", e.err);_x000D_ return 0;_x000D_ } |
| A. | 0 |
| B. | 1 |
| C. | 2 |
| D. | Error |
| Answer» C. 2 | |
| 23. |
What will be the output of the program?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ typedef int arr[5];_x000D_ arr iarr = {1, 2, 3, 4, 5};_x000D_ int i;_x000D_ for(i=0; i |
| A. | 1, 2, 3, 4 |
| B. | 1, 2, 3, 4, 5 |
| C. | No output |
| D. | Error: Cannot use typedef with an array |
| Answer» B. 1, 2, 3, 4, 5 | |
| 24. |
What will be the output of the program?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ typedef int LONG;_x000D_ LONG a=4;_x000D_ LONG b=68;_x000D_ float c=0;_x000D_ c=b;_x000D_ b+=a;_x000D_ printf("%d,", b);_x000D_ printf("%f\n", c);_x000D_ return 0;_x000D_ } |
| A. | 72, 68.000000 |
| B. | 72.000000, 68 |
| C. | 68.000000, 72.000000 |
| D. | 68, 72.000000 |
| Answer» B. 72.000000, 68 | |
| 25. |
Are the properties of i, j and x, y in the following program same?_x000D_ typedef unsigned long int uli;_x000D_ uli i, j;_x000D_ unsigned long int x, y; |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 26. |
One of the major difference between typedef and #define is that typedef interpretation is performed by the _________________ whereas #define interpretation is performed by the _____________ |
| A. | pre-processor, compiler |
| B. | user, pre-processor |
| C. | compiler, pre-processor |
| D. | compiler, user |
| Answer» D. compiler, user | |
| 27. |
Consider this statement: typedef enum good {a, b, c} hello; Which of the following statements is incorrect about hello? |
| A. | hello is a typedef of enum good |
| B. | hello is a structure |
| C. | hello is a variable of type enum good |
| D. | the statement shown above is erroneous |
| Answer» B. hello is a structure | |
| 28. |
What is the size of myArray in the code shown below? (Assume that 1 character occupies 1 byte) |
| A. | 5 bytes |
| B. | 10 bytes |
| C. | 40 bytes |
| D. | 50 bytesView Answer |
| E. | a) 5 bytesb) 10 bytesc) 40 bytesd) 50 bytesView Answer |
| Answer» E. a) 5 bytesb) 10 bytesc) 40 bytesd) 50 bytesView Answer | |
| 29. |
The keyword typedef cannot be used to give alias names to pointers. |
| A. | True |
| B. | False |
| Answer» C. | |
| 30. |
We want to create an alias name for an identifier of the type unsigned long. The alias name is: ul. The correct way to do this using the keyword typedef is ____________ |
| A. | typedef unsigned long ul; |
| B. | unsigned long typedef ul; |
| C. | typedef ul unsigned long; |
| D. | ul typedef unsigned long; |
| Answer» B. unsigned long typedef ul; | |
| 31. |
Which of the following keywords is used to define an alternate name for an already existing data type? |
| A. | default |
| B. | volatile |
| C. | typedef |
| D. | static |
| Answer» D. static | |
| 32. |
What will be the output of the program? #include int main() { typedef float f; static f *fptr; float fval = 90; fptr = &fval; printf("%f\n", *fptr); return 0; } |
| A. | 9 |
| B. | 0 |
| C. | 90 |
| D. | 90 |
| Answer» D. 90 | |
| 33. |
What will be the output of the program? #include int main() { typedef int LONG; LONG a=4; LONG b=68; float c=0; c=b; b+=a; printf("%d,", b); printf("%f\n", c); return 0; } |
| A. | 72, 68.000000 |
| B. | 72.000000, 68 |
| C. | 68.000000, 72.000000 |
| D. | 68, 72.000000 |
| Answer» B. 72.000000, 68 | |
| 34. |
What will be the output of the program? #include int main() { typedef int arr[5]; arr iarr = {1, 2, 3, 4, 5}; int i; for(i=0; i |
| A. | 1, 2, 3, 4 |
| B. | 1, 2, 3, 4, 5 |
| C. | No output |
| D. | Error: Cannot use typedef with an array |
| Answer» B. 1, 2, 3, 4, 5 | |
| 35. |
Is there any difference in the #define and typedef in the following code? typedef char * string_t; #define string_d char *; string_t s1, s2; string_d s3, s4; |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 36. |
Point out the error in the following code? typedef struct { int data; NODEPTR link; }*NODEPTR; |
| A. | Error: in *NODEPTR |
| B. | Error: typedef cannot be used until it is defined |
| C. | No error |
| D. | None of above |
| Answer» C. No error | |
| 37. |
What will be the output of the program? #include typedef struct error {int warning, err, exception;} ERROR; int main() { ERROR e; e.err=1; printf("%d\n", e.err); return 0; } |
| A. | 0 |
| B. | 1 |
| C. | 2 |
| D. | Error |
| Answer» C. 2 | |
| 38. |
Are the properties of i, j and x, y in the following program same? typedef unsigned long int uli; uli i, j; unsigned long int x, y; |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 39. |
typedef's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas #define's always have a global effect. |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 40. |
What is x in the following program? #include int main() { typedef char (*(*arrfptr[3])())[10]; arrfptr x; return 0; } |
| A. | x is a pointer |
| B. | x is an array of three pointer |
| C. | x is an array of three function pointers |
| D. | Error in x declaration |
| Answer» D. Error in x declaration | |
| 41. |
In the following code what is 'P'? typedef char *charp; const charp P; |
| A. | P is a constant |
| B. | P is a character constant |
| C. | P is character type |
| D. | None of above |
| Answer» B. P is a character constant | |
| 42. |
What will be the output of the program? #include int main() { enum color{red, green, blue}; typedef enum color mycolor; mycolor m = red; printf("%d", m); return 0; } |
| A. | 1 |
| B. | 0 |
| C. | 2 |
| D. | red |
| Answer» C. 2 | |
| 43. |
Is the following declaration acceptable? typedef long no, *ptrtono; no n; ptrtono p; |
| A. | Yes |
| B. | NO |
| C. | Yes |
| D. | No |
| Answer» B. NO | |
| 44. |
In the following code snippet can we declare a new typedef named ptr even though struct employee has not been completely declared while using typedef? typedef struct employee *ptr; struct employee { char name[20]; int age; ptr next; } |
| A. | Yes |
| B. | No |
| C. | Error: in *NODEPTR |
| D. | Error: typedef cannot be used until it is defined |
| Answer» B. No | |
| 45. |
In the following code, the P2 is Integer Pointer or Integer? typedef int *ptr; ptr p1, p2; |
| A. | Integer |
| B. | Integer pointer |
| C. | Error in declaration |
| D. | None of above |
| Answer» C. Error in declaration | |