Explore topic-wise MCQs in C Programming.

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

What will be the output of the code snippet given below?
#include <studio.h>
int main ()
{
struct book
{
char bookname[20];
int totalpages;
float price;
};
struct book b = {0};
printf(("%d%f n", b.totalpages, b.price);
return 0;
}

A. 0 0.000000
B. Garbage values
C. Erroe
D. None of the above
Answer» B. Garbage values
2.

Which of the following is the correct output fot the program given below?
#include <studio.h>
int main ()
{
struct emp
{
char name[40];
int age;
float sal;
};
struct emp e = {"Ramu"};
printf ("%d %f n", e.age, e.sal);
return 0;
}

A. 0 0.000000
B. Garbage values
C. Error
D. None of the above
Answer» B. Garbage values
3.

Which of the following will stop the loop at the last node of a linked list in the following C code snippet?
struct node
{
struct node *next;
};

A. All of above
B. None of these
Answer» B. None of these
4.

The number of distinct nodes the following struct declaration can point to is _____________.
struct node
{
struct node *left;
struct node *centre;
struct node *right;
};

A. 3
B. 2
C. 1
D. All of above
E. None of these
Answer» E. None of these
5.

What will be the output of the following C code?
#include <stdio.h>
struct MansWear
{
int size1;
int size2;
};
struct WomensWear
{
int size1;
int size2;
};
void fun(struct MansWear);
int main()
{
struct WomensWear WW = {39, 42};
fun(WW);
}
void fun(struct MansWear MW)
{
printf("%d n", MW.size1);
}

A. Compilation Error
B. 39
C. 42
D. Garbage value
E. None of these
Answer» B. 39
6.

What will be the output of the following C code?
#include <stdio.h>
struct country
{
int code;
char name[26];
}
void main()
{
struct country c;
c.code = 91;
printf("India");
}

A. Garbage value
B. India
C. 91
D. Compilation Error
E. None of these
Answer» E. None of these
7.

What will be the output of the following C code?
#include <stdio.h>
struct test
{
int num;
} t;
void func(struct test t)
{
t.num = 125;
printf("%d ", t.num);
}
main()
{
func(t);
printf("%d ", t.num);
}

A. Compilation Error
B. 125 0
C. Garbage value
D. Nothing
E. None of these
Answer» C. Garbage value
8.

What will be the output of the following C code?
#include <stdio.h>
struct option1
{
int m;
int n;
};
struct option2
{
int m;
int n;
};
int main()
{
struct option1 opt1 = {10};
struct option2 opt2 = opt1;
printf("%d n", opt2.m);
}

A. Garbage value
B. 0
C. 10
D. Compilation Error
E. None of these
Answer» E. None of these
9.

What will be the output of the following C code?
#include <stdio.h>
struct option1
{
int m;
int n;
};
struct option2
{
int m;
int n;
};
struct option1 fun();
int main()
{
struct option1 opt1 = {11};
struct option2 opt2 = {21, 31};
opt2 = fun();
printf("%d n", opt2.m);
}
struct option1 fun()
{
struct option1 temp = {11, 21};
return temp;
}

A. 21
B. 11
C. Compilation Error
D. Undefined behaviour
E. None of these
Answer» D. Undefined behaviour
10.

What will be the output of the following C code?
#include <stdio.h>
struct Calc
{
int m;
int n;
};
int main()
{
struct Calc c = {10};
struct Calc c1 = {11};
if(c == c1)
printf("Equal n");
else
printf("Not Equal n");
}

A. Equal
B. Not Equal
C. Garbage value
D. Compilation Error
E. None of these
Answer» E. None of these
11.

What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *Name;
};
struct Employee fun(void)
{
struct Employee emp1;
emp1.Name = "Prayag";
return emp1;
}
void main()
{
struct Employee emp2 = fun();
emp1.Name = "Ajit";
printf("%s", emp2.Name);
}

A. Prayag
B. Ajit
C. Compilation Error
D. Garbage value
E. None of these
Answer» D. Garbage value
12.

The correct syntax to access the member of the ith structure in the array of structures is?
Assuming: struct temp
{
int n;
}sct[30];

A. sct[j].n;
B. sct.n[j];
C. sct.[j].n;
D. sct.n.[j];
E. None of these
Answer» B. sct.n[j];
13.

What will be the output of the following C code?
#include <stdio.h>
struct Country
{
char *name;
};
struct Country function(void)
{
struct Country cnt1;
cnt1.name = "India";
return cnt1;
}
void main()
{
struct Country cnt2 = function();
printf("%s", cnt2.name);
}

A. India
B. Compilation Error
C. Garbage value
D. Nothing
E. None of these
Answer» B. Compilation Error
14.

What will be the output of the following C code?
#include <stdio.h>
struct B
{
int m;
char n;
float t;
};
int B = 55;
int main()
{
struct B z = {10, 99};
printf("%f %d n", z.t, B);
}

A. Compilation Error
B. 0.000000 55
C. Garbage value
D. depends on compiler
E. None of these
Answer» C. Garbage value
15.

What will be the output of the following C code?
 #include <stdio.h>
struct A
{
int n;
char m;
};
int A = 150;
int main()
{
struct A z;
z.n = 150;
printf("%d %d n", z.n, A);
}

A. 150 150
B. Compilation Error
C. Garbage value
D. Nothing
E. None of these
Answer» B. Compilation Error
16.

What will be the output of the following C code?
#include <stdio.h>
struct
{
int n;
char m;
} stru;
int stru = 110;
int main()
{
stru.n = 110;
printf("%d %d n", stru.n, stru);
}

A. 110 110
B. Compilation Error
C. Garbage value
D. Undefined behaviour
E. None of these
Answer» C. Garbage value
17.

What will be the output of the following C code?
#include <stdio.h>
struct
{
int i;
char a;
};
int main()
{
struct stru;
stru.i = 100;
printf("%d n", stru.i);
}

A. Compilation Error
B. Garbage value
C. Nothing
D. 100
E. None of these
Answer» B. Garbage value
18.

How many bytes in memory taken by the following C structure?
#include 
struct Example
{
int i;
char a;
};

A. Multiple of word size
B. Depends on the platform
C. integer size+character size
D. Multiple of integer size
E. None of these
Answer» E. None of these
19.

What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *name;
};
struct Employee emp[2];
void main()
{
emp[0].name = "Ajit";
emp[1] = emp[0];
printf("%s %s", emp[0].name, emp[1].name);
emp[1].name = "Sujit";
printf(" %s %s", emp[0].name, emp[1].name);
}

A. Ajit Ajit Ajit Sujit
B. Sujit Ajit Ajit Ajit
C. Sujit Ajit
D. Compilation Error
E. None of these
Answer» B. Sujit Ajit Ajit Ajit
20.

What will be the output of the following C code? (Assuming size of int be 4)
#include <stdio.h>
struct Count
{
int n1;
int n2;
int n3;
} cnt[] = {0};
main()
{
printf("%d", sizeof(cnt));
}

A. 16
B. 12
C. 4
D. Compilation Error
E. None of these
Answer» C. 4
21.

Comment on the output of the following C code.
#include <stdio.h>
struct Number
{
int n1;
int n2;
int n3;
};
main()
{
struct Number num[] = {{12, 22, 32}, {24, 25, 26}, {27, 28, 29}};
}

A. No Compile time error, generates an array of structure of size 9
B. Compile time error, illegal declaration of a multidimensional array
C. Compile time error, illegal assignment to members of structure
D. No Compile time error, generates an array of structure of size 3
E. None of these
Answer» E. None of these
22.

What will be the output of the following C code?
#include <stdio.h7gt;
struct City function(void)
{
struct City
{
char *name;
};
struct City c1;
c1.name = "Patna";
return c1;
}
void main()
{
struct City c2 = function();
printf("%s", c2.name);
}

A. India
B. Garbage value
C. Undefined behaviour
D. Compilation Error
E. None of these
Answer» E. None of these
23.

What will be the output of the following C code?
#include <stdio.h>
struct Item
{
int s;
int t;
};
void function(struct Item*);
int main()
{
struct Item I = {33, 44};
function(&I);
}
void function(struct Item *ptr)
{
printf("%d n", *ptr->s++);
}

A. 33
B. Compilation Error
C. 44
D. Garbage value
E. None of these
Answer» C. 44
24.

What will be the output of the following C code?
#include <stdio.h>
struct furniture
{
int a;
int b;
};
void fun(struct furniture*);
int main()
{
struct furniture frn1 = {12, 22};
fun(&frn1);
}
void fun(struct point *ptr)
{
printf("%d n", *ptr.a++);
}

A. Compilation Error
B. 12
C. Segmentation fault/code crash
D. 22
E. None of these
Answer» B. 12
25.

What will be the output of the following C code?
#include <stdio.h>
struct Option
{
int t1;
int t2;
};
void fun(struct Option*);
int main()
{
struct Option opt1[] = {12, 22, 23, 24, 25};
fun(opt1);
}
void fun(struct Option opt[])
{
printf("%d %d n", opt->t1, (opt + 2)->t2);
}

A. 12 0
B. Compilation Error
C. 12 garbage value
D. Nothing
E. undefined behaviour
Answer» B. Compilation Error
26.

What will be the output of the following C code?
#include <stdio.h>
struct Count
{
int m;
int n;
};
void fun(struct Count*);
int main()
{
struct Count c1[] = {14, 24, 34, 44, 54};
fun(c1);
}
void fun(struct Count c2[])
{
printf("%d %d n", c2->m, (c2 + 2).n);
}

A. 24
B. 34
C. 44
D. 54
E. Compilation Error
Answer» F.
27.

What will be the output of the following C code?
 #include &l;stdio.h>
struct Price
{
int m;
int n;
};
void fun(struct Price*);
int main()
{
struct Price p1[] = {105, 210, 310, 49, 59};
fun(p1);
}
void fun(struct Price p[])
{
printf("%d %d n", p->m, p[3].n);
}

A. Garbage value
B. Compilation Error
C. 105 0
D. Nothing
E. None of these
Answer» D. Nothing
28.

What will be the output of the following C code?
#include <stdio.h>
struct Team
{
int a;
int b;
};
void function(struct Team*);
int main()
{
struct Team t1[] = {100, 200, 300, 400};
function(t1);
}
void function(struct Team t2[])
{
printf("%d %d n", t2->a, ++t2->a);
}

A. 100 200
B. 300 400
C. 101 101
D. Garbage value
E. None of these
Answer» D. Garbage value
29.

What will be the output of the following C code?
#include <stdio.h>
struct Cricket_Team
{
int A;
int B;
} t[] = {150, 250, 350, 450, 550};
void function(struct Cricket_Team*);
int main()
{
function(t);
}
void function(struct Cricket_Team t[])
{
printf("%d %d n", t->A, t[2].B);
}

A. Compilation Error
B. Garbage value
C. Undefined behaviour
D. 150 0
E. None of these
Answer» E. None of these
30.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
int x;
char y;
};
void foo(struct p* );
int main()
{
typedef struct p* q;
struct p p1[] = {15, 52, 43, 34, 25, 16};
foo(p1);
}
void foo(struct p* p1)
{
q ptr1 = p1;
printf("%d n", ptr1->x);
}

A. Undefined behaviour
B. 15
C. Compilation Error
D. Segmentation fault
E. None of these
Answer» D. Segmentation fault
31.

What will be the output of the following C code?
#include <stdio.h>
struct price
{
int s1;
char s2;
};
typedef struct price* ptr*;
int main()
{
struct price pr[] = {15, 52, 35, 95, 55, 56};
ptr ptr1 = pr;
printf("%d n", ptr1->s1);
}

A. Compilation Error
B. Garbage value
C. Segmentation fault
D. Undefined behaviour
E. None of these
Answer» B. Garbage value
32.

What will be the output of the following C code?
#include <stdio.h>
struct Example
{
int n;
} e;
void fun(struct Example);
main()
{
e.n = 101;
fun(e);
printf("%d n", e.n);
}
void fun(struct Example e)
{
e.n = 1;
}

A. Compilation Error
B. Garbage value
C. 101
D. Nothing
E. None of these
Answer» D. Nothing
33.

Which option is not possible for the following function call?
func(&stru.num); //where stru is a variable of type struct and num is the member of the struct.

A. Individual member can be passed by reference in a function
B. Individual member s address can be displayed in structure
C. Compiler can access entire structure from the function
D. All of above
E. None of these
Answer» D. All of above
34.

Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?
(Assume: struct example{int num;} e;)

A. func(&(e).num);
B. func(&(e.num));
C. func(&e.num);
D. All of above
E. None of these
Answer» F.
35.

Which of the following is an incorrect syntax for pointer to structure?
(Assuming struct test{int n;}*ptr_struct;)

A. (*ptr_struct).n = 110;
B. ptr_struct->n = 110;
C. *ptr_struct.n = 110;
D. Both (*ptr_struct).n = 110; and *ptr_struct.n = 110;
E. None of these
Answer» D. Both (*ptr_struct).n = 110; and *ptr_struct.n = 110;
36.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *ch;
};
void main()
{
struct student m;
struct student *s = &m;
(*s).ch = "Welcome";
printf("%s", m.ch);
}

A. Welcome
B. Garbage value
C. Nothing
D. Compilation Error
E. None of these
Answer» B. Garbage value
37.

What will be the output of the following C code?
#include <stdio.h>
struct City
{
char *ch;
};
void main()
{
struct City c1;
struct City *c2 = &c1;
c2->ch = "Patna";
printf("%s", c1.ch);
}

A. Compilation Error
B. Garbage value
C. Segmentation fault
D. Patna
E. None of these
Answer» E. None of these
38.

What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *ch;
};
void main()
{
struct Employee *e;
e->ch = "Prayag";
printf("%s", e->ch);
}

A. Compilation Error
B. Segmentation fault
C. Garbage value
D. Prayag
E. None of these
Answer» C. Garbage value
39.

What will be the output of the following C code?
#include <stdio.h>
struct Company
{
char *ch;
};
void main()
{
struct Company c1;
struct Company *c2 = &c1;
c2->ch = "Interview Mania";
printf("%s", c2->ch);
}

A. Interveiw
B. Mania
C. Compilation Error
D. Interview Mania
E. None of these
Answer» E. None of these
40.

What will be the output of the following C code?
#include <stdio.h>
struct option
{
int n1;
int n2;
};
int main()
{
struct option opt1[] = {101, 97, 32, 91, 52, 91};
struct option *ptr1 = opt1;
int n1 = (sizeof(opt1) / 5);
if (n1 == 3)
printf("%d %d n", ptr1->n1, (ptr1 + n1 - 1)->n1);
else
printf("False n");
}

A. Undefined behaviour
B. Compilation Error
C. Garbage value
D. Nothing
E. False
Answer» F.
41.

What will be the output of the following C code?
 #include <stdio.h>
struct output
{
int n1;
char n2;
};
int main(){
struct output out[] = {100, 90, 13, 95, 55, 92};
struct output *ptr1 = out;
int n1 = (sizeof(out) / sizeof(struct output));
printf("%d %d n", ptr1->n1, (ptr1 + n1 - 1)->n1);
}

A. 100 90
B. 13 95
C. 55 92
D. 100 55
E. None of these
Answer» E. None of these
42.

What will be the output of the following C code?
 #include <stdio.h>
struct output
{
int n1;
int n2;
};
int main()
{
struct output out[] = {11, 21, 13, 41, 15, 61};
struct output *ptr1 = out;
printf("%d %d n", ptr1->n1, (ptr1 + 2)->n1);
}

A. Compilation Error
B. 11 21
C. 13 41
D. 11 15
E. None of these
Answer» E. None of these
43.

What will be the output of the following C code?
#include <stdio.h>
struct point1
{
int x[2];
};
struct point2
{
int *x;
};
int main()
{
struct point1 p1 = {11, 22};
struct point2 *ptr1 = (struct q*)&p1;
ptr1->x = (struct q*)&p1.x;
printf("%d n", ptr1->x[0]);
}

A. Compilation Error
B. Segmentation fault
C. Undefined behaviour
D. Runtime Error
E. None of these
Answer» D. Runtime Error
44.

What will be the output of the following C code?
#include <stdio.h>
struct calculation1
{
int n[2];
};
struct calculation2
{
int *n;
};
int main()
{
struct calculation1 cal1 = {10, 20};
struct calculation2 *ptr1;
ptr1->n = (struct q*)&cal1.n;
printf("%d n", ptr1->n[1]);
}

A. Segmentation fault
B. Garbage value
C. Compilation Error
D. 20
E. None of these
Answer» B. Garbage value
45.

What will be the output of the following C code?
 #include <stdio.h>
struct Employee
{
char *ch;
};
void main()
{
struct Employee e;
struct Employee *s = &e;
(*s).ch = "Interview Mania";
printf("%p n%p n", s, &e);
}

A. Interview Mania
B. Different memory address
C. Same memory address
D. Compilation Error
E. None of these
Answer» D. Compilation Error
46.

What will be the output of the following C code?
#include <stdio.h>
struct Result
{
int n1;
char n2;
struct Result *p;
};
int main()
{
struct Result Result = {100, 200, &Result};
printf("%d n", Result.p->n1);
return 0;
}

A. 200
B. Compilation Error
C. 100
D. Undefined behaviour
E. None of these
Answer» D. Undefined behaviour
47.

What will be the output of the following C code?
 #include <stdio.h>
struct Employee
{
char *ch;
struct Employee *point;
};
void main()
{
struct Employee e1;
struct Employee *e2 = &e1;
printf("%d", sizeof(Employee));
}

A. Undefined behaviour
B. Nothing
C. Garbage value
D. Compilation Error
E. None of these
Answer» E. None of these
48.

What will be the output of the following C code?
#include <stdio.h>
struct Man
{
char *ch;
struct Man *point;
};
void main()
{
struct Man m;
printf("%d", sizeof(m));
}

A. 4
B. 8
C. 16
D. Compilation Error
E. None of these
Answer» E. None of these
49.

What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *ch;
struct Employee *point;
};
void main()
{
struct Employee e1;
struct Employee e2;
e2.point = e1;
(e2.point)->ch = "Prayag";
printf("%s", e1.ch);
}

A. Compilation Error
B. Garbage value
C. Prayag
D. Undefined behaviour
E. None of these
Answer» B. Garbage value
50.

What will be the output of the following C code?
#include <stdio.h>
struct Company
{
char *ch;
struct Company *point;
};
void main()
{
struct Company c1;
struct Company c2;
c1.ch = c2.ch = "Interview";
c2.point = &c1;
(c2.point)->ch = "Mania";
printf("%s %s t", c1.ch, c2.ch);
}

A. Interview
B. Mania
C. Interview Mania
D. Mania Interview
E. None of these
Answer» E. None of these