Explore topic-wise MCQs in C Programming.

This section includes 66 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.

On declaring a structure 0 bytes are reserved in memory.

A. True
B. False
Answer» C.
2.

If the following structure is written to a file using , can read it back successfully?

A. Yes
B. No
Answer» C.
3.

Will the following code work?

A. Yes
B. No
Answer» B. No
4.

What will be the output of the program in Turbo C (under DOS)?

A. Error: Invalid structure assignment
B. DRAVID
C. Dravid
D. No output
Answer» C. Dravid
5.

What will be the output of the program in 16-bit platform (under DOS)?

A. 2, 2
B. 8, 8
C. 5, 5
D. 4, 4
Answer» B. 8, 8
6.

Will the following declaration work?

A. Yes
B. No
Answer» B. No
7.

If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?

A. Yes
B. No
Answer» C.
8.

Which of the following statements correct about the below program?

A. Error:
B. function cannot be used for structures elements.
C. The code runs successfully.
D. Error: Floating point formats not linked Abnormal program termination.
E. Error: structure variable must be initialized.
Answer» D. Error: Floating point formats not linked Abnormal program termination.
9.

Which of the following statements correct about the below program?

A. 1, 2
B. 2, 3
C. 1, 2, 3
D. 1, 3, 4
Answer» D. 1, 3, 4
10.

Which of the following statements correctly assigns 12 to using pointer variable ?

A. pdt.month = 12
B. &pdt.month = 12
C. d.month = 12
D. pdt->month = 12
Answer» E.
11.

What will be the output of the program in 16 bit platform (Turbo C under DOS) ?

A. 1
B. 2
C. 4
D. 9
Answer» C. 4
12.

Point out the error in the program in 16-bit platform?

A. 4
B. 2
C. Error: Bit field too large
D. Error: Invalid member access in structure
Answer» D. Error: Invalid member access in structure
13.

What will be the output of the program given below in 16-bit platform ?

A. 1
B. 2
C. 4
D. 10
Answer» C. 4
14.

What will be the output of the program ? #include int main() { union a { int i; char ch[2]; }; union a u; u.ch[0]=3; u.ch[1]=2; printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); return 0; }

A. 3, 2, 515
B. 515, 2, 3
C. 3, 2, 5
D. 515, 515, 4
Answer» B. 515, 2, 3
15.

What will be the output of the program ? #include struct course { int courseno; char coursename[25]; }; int main() { struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} }; printf("%d ", c[1].courseno); printf("%s\n", (*(c+2)).coursename); return 0; }

A. 103 DotNet
B. 102 Java
C. 103 PHP
D. 104 DotNet
Answer» B. 102 Java
16.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ int i=4, j=8;_x000D_ printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);_x000D_ return 0;_x000D_ }

A. 12, 12, 12
B. 112, 1, 12
C. 32, 1, 12
D. -64, 1, 12
Answer» B. 112, 1, 12
17.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ enum status {pass, fail, absent};_x000D_ enum status stud1, stud2, stud3;_x000D_ stud1 = pass;_x000D_ stud2 = absent;_x000D_ stud3 = fail;_x000D_ printf("%d %d %d\n", stud1, stud2, stud3);_x000D_ return 0;_x000D_ }

A. 0, 1, 2
B. 1, 2, 3
C. 0, 2, 1
D. 1, 3, 2
Answer» D. 1, 3, 2
18.

Which of the following statements correctly assigns 12 to month using pointer variable pdt? #include struct date { int day; int month; int year; }; int main() { struct date d; struct date *pdt; pdt = &d; return 0; }

A. pdt.month = 12
B. &pdt.month = 12
C. d.month = 12
D. pdt->month = 12
Answer» E.
19.

What will be the output of the program ? #include int main() { struct byte { int one:1; }; struct byte var = {1}; printf("%d\n", var.one); return 0; }

A. 1
B. -1
C. 0
D. Error
Answer» C. 0
20.

Which of the following statements correct about the below program? #include int main() { struct emp { char name[25]; int age; float sal; }; struct emp e[2]; int i=0; for(i=0; i<2; i++) scanf("%s %d %f", e[i].name, &e[i].age, &e[i].sal); for(i=0; i<2; i++) scanf("%s %d %f", e[i].name, e[i].age, e[i].sal); return 0; }

A. Error: scanf() function cannot be used for structures elements.
B. The code runs successfully.
C. Error: Floating point formats not linked Abnormal program termination.
D. Error: structure variable must be initialized.
Answer» D. Error: structure variable must be initialized.
21.

Which of the following statements correct about the below code?_x000D_ maruti.engine.bolts=25;

A. Structure bolts is nested within structure engine.
B. Structure engine is nested within structure maruti.
C. Structure maruti is nested within structure engine.
D. Structure maruti is nested within structure bolts.
Answer» C. Structure maruti is nested within structure engine.
22.

What will be the output of the program in 16-bit platform (under DOS)? #include int main() { struct node { int data; struct node *link; }; struct node *p, *q; p = (struct node *) malloc(sizeof(struct node)); q = (struct node *) malloc(sizeof(struct node)); printf("%d, %d\n", sizeof(p), sizeof(q)); return 0; }

A. 2, 2
B. 8, 8
C. 5, 5
D. 4, 4
Answer» B. 8, 8
23.

Point out the error in the program? #include int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; e.age = 25; printf("%s %d\n", e.name, e.age); return 0; }

A. Error: Lvalue required/incompatible types in assignment
B. Error: invalid constant expression
C. Error: Rvalue required
D. No error, Output: Suresh 25
Answer» B. Error: invalid constant expression
24.

Which of the following statements correct about the below program?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ union a_x000D_ {_x000D_ int i;_x000D_ char ch[2];_x000D_ };_x000D_ union a u1 = {512};_x000D_ union a u2 = {0, 2};_x000D_ return 0;_x000D_ }_x000D_ _x000D_ _x000D_ 1:_x000D_ u2 CANNOT be initialized as shown._x000D_ _x000D_ _x000D_ 2:_x000D_ u1 can be initialized as shown._x000D_ _x000D_ _x000D_ 3:_x000D_ To initialize char ch[] of u2 '.' operator should be used._x000D_ _x000D_ _x000D_ 4:_x000D_ The code causes an error 'Declaration syntax error'

A. 1, 2
B. 2, 3
C. 1, 2, 3
D. 1, 3, 4
Answer» D. 1, 3, 4
25.

Point out the error in the program? #include int main() { union a { int i; char ch[2]; }; union a z1 = {512}; union a z2 = {0, 2}; return 0; }

A. Error: invalid union declaration
B. Error: in Initializing z2
C. No error
D. None of above
Answer» C. No error
26.

Point out the error in the program? #include int main() { struct emp { char name[20]; float sal; }; struct emp e[10]; int i; for(i=0; i<=9; i++) scanf("%s %f", e[i].name, &e[i].sal); return 0; }

A. Error: invalid structure member
B. Error: Floating point formats not linked
C. No error
D. None of above
Answer» C. No error
27.

Point out the error in the program? #include int main() { struct a { float category:5; char scheme:4; }; printf("size=%d", sizeof(struct a)); return 0; }

A. Error: invalid structure member in printf
B. Error in this float category:5; statement
C. No error
D. None of above
Answer» C. No error
28.

Point out the error in the program in 16-bit platform? #include int main() { struct bits { int i:40; }bit; printf("%d\n", sizeof(bit)); return 0; }

A. 4
B. 2
C. Error: Bit field too large
D. Error: Invalid member access in structure
Answer» D. Error: Invalid member access in structure
29.

What will be the output of the program ? #include int main() { union var { int a, b; }; union var v; v.a=10; v.b=20; printf("%d\n", v.a); return 0; }

A. 10
B. 20
C. 30
D. 0
Answer» C. 30
30.

If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes? struct ex { char ch; int i; long int a; };

A. Yes
B. No
Answer» C.
31.

Point out the error in the program? #include int main() { struct bits { float f:2; }bit; printf("%d\n", sizeof(bit)); return 0; }

A. 4
B. 2
C. Error: cannot set bit field for float
D. Error: Invalid member access in structure
Answer» D. Error: Invalid member access in structure
32.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};_x000D_ printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);_x000D_ return 0;_x000D_ }

A. -1, 0, 1, 2, 3, 4
B. -1, 2, 6, 3, 4, 5
C. -1, 0, 6, 2, 3, 4
D. -1, 0, 6, 7, 8, 9
Answer» E.
33.

If the following structure is written to a file using fwrite(), can fread() read it back successfully?_x000D_ struct emp_x000D_ {_x000D_ char *n;_x000D_ int age;_x000D_ };_x000D_ struct emp e={"IndiaBIX", 15};_x000D_ FILE *fp;_x000D_ fwrite(&e, sizeof(e), 1, fp);

A. Yes
B. No
Answer» C.
34.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};_x000D_ printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT);_x000D_ return 0;_x000D_ }

A. -1, 0, 1, 2, 3, 4
B. Error
C. 0, 1, 6, 3, 4, 5
D. 0, 0, 6, 7, 8, 9
Answer» C. 0, 1, 6, 3, 4, 5
35.

What will be the output of the program in Turbo C (under DOS)? #include int main() { struct emp { char *n; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; strupr(e2.n); printf("%s\n", e1.n); return 0; }

A. Error: Invalid structure assignment
B. DRAVID
C. Dravid
D. No output
Answer» C. Dravid
36.

Point out the error in the program? #include int main() { struct emp { char n[20]; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; if(e1 == e2) printf("The structure are equal"); return 0; }

A. Prints: The structure are equal
B. Error: Structure cannot be compared using '=='
C. No output
D. None of above
Answer» C. No output
37.

What will be the output of the program given below in 16-bit platform ? #include int main() { enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var; printf("%d\n", sizeof(var)); return 0; }

A. 1
B. 2
C. 4
D. 10
Answer» C. 4
38.

What will be the output of the program ? #include int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit={1, 2, 13}; printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4); return 0; }

A. 1, 2, 13
B. 1, 4, 4
C. -1, 2, -3
D. -1, -2, -13
Answer» D. -1, -2, -13
39.

What will be the output of the program in 16 bit platform (Turbo C under DOS) ? #include int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf("%d\n", sizeof(bit)); return 0; }

A. 1
B. 2
C. 4
D. 9
Answer» C. 4
40.

Will the following code work? #include #include struct emp { int len; char name[1]; }; int main() { char newname[] = "Rahul"; struct emp *p = (struct emp *) malloc(sizeof(struct emp) -1 + strlen(newname)+1); p->len = strlen(newname); strcpy(p -> name, newname); printf("%d %s\n", p->len, p->name); return 0; }

A. Yes
B. No
Answer» B. No
41.

Point out the error in the program? typedef struct data mystruct; struct data { int x; mystruct *b; };

A. Error: in structure declaration
B. Linker Error
C. No Error
D. None of above
Answer» D. None of above
42.

Point out the error in the program? struct emp { int ecode; struct emp e; };

A. Error: in structure declaration
B. Linker Error
C. No Error
D. None of above
Answer» B. Linker Error
43.

Point out the error in the program? struct emp { int ecode; struct emp *e; };

A. Error: in structure declaration
B. Linker Error
C. No Error
D. None of above
Answer» D. None of above
44.

Point out the error in the program? #include #include void modify(struct emp*); struct emp { char name[20]; int age; }; int main() { struct emp e = {"Sanjay", 35}; modify(&e); printf("%s %d", e.name, e.age); return 0; } void modify(struct emp *p) { p ->age=p->age+2; }

A. Error: in structure
B. Error: in prototype declaration unknown struct emp
C. No error
D. None of above
Answer» C. No error
45.

Will the following declaration work? typedef struct s { int a; float b; }s;

A. Yes
B. No
Answer» B. No
46.

Which of the following technique is faster for travelling in binary trees?

A. Iteration
B. Recursion
C. Both Iteration and Recursion
D. Depends from compiler to compiler
Answer» C. Both Iteration and Recursion
47.

Which of the following is not possible regarding structure variable?

A. A structure variable pointing to itself
B. A structure variable pointing to another structure variable of same type
C. 2 different type of structure variable pointing at each other
D. None of the mentioned
Answer» E.
48.

Presence of code like 's.t.b = 10' indicates __________

A. Syntax Error
B. Structure
C. double data type
D. An ordinary variable name
Answer» C. double data type
49.

What is typedef declaration?

A. Does not create a new type
B. It merely adds a new name for some existing type
C. Does not create a new type, It merely adds a new name for some existing type
D. None of the mentioned
Answer» D. None of the mentioned
50.

The size of a union is determined by the size of the __________

A. First member in the union
B. Last member in the union
C. Biggest member in the union
D. Sum of the sizes of all members
Answer» D. Sum of the sizes of all members