Explore topic-wise MCQs in C Programming.

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

Calculate the % of memory saved when bit-fields are used for the following C structure as compared to with-out use of bit-fields for the same structure? (Assuming size of int = 4)
struct test
{
int p : 1;
int q : 2;
int r : 4;
int s : 4;
}stu;

A. 75%
B. 50%
C. 33.3%
D. 25%
E. None of these
Answer» B. 50%
2.

For what minimum value of x in a 32-bit Linux OS would make the size of e equal to 8 bytes?
struct Example
{
int n : 13;
int m : 8;
int s : n;
}e;

A. 32
B. 12
C. 8
D. 4
E. None of these
Answer» C. 8
3.

What is the order for the following C declarations?
short n1 : 26;
int long n2 : 30;

A. Illegal, legal
B. Legal, legal
C. Legal, illegal
D. Illegal, illegal
E. None of these
Answer» E. None of these
4.

What will be the output of the following C code?
 #include <stdio.h>
union Un
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}s;
int x;
};
int main()
{
union Un u.s.x = 2;
printf("%d n", Un.s.x);
}

A. Compilation Error
B. Garbage value
C. 2
D. Nothing
E. Undefined behaviour
Answer» B. Garbage value
5.

What will be the output of the following C code?
#include <stdio.h>
union Un
{
struct
{
unsigned char c : 1;
unsigned int n : 2;
}Stru;
int ch;
};
int main()
{
union Un u;
u.Stru.c = 1;
printf("%d n", u.Stru.c);
}

A. 0
B. 1
C. 2
D. Garbage value
E. Compilation Error
Answer» C. 2
6.

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

A. 1
B. 2
C. 0
D. Compilation Error
E. None of these
Answer» D. Compilation Error
7.

What will be the output of the following C code?
#include <stdio.h>
union Un
{
struct str
{
unsigned char ch : 2;
unsigned int n : 2;
};
int ch;
};
int main()
{
union Un u;
Un.str.ch = 2;
printf("%d n", Un.str.ch);
}

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

What will be the output of the following C code?
#include <stdio.h>
union Un
{
struct
{
unsigned char ch : 2;
unsigned int n : 2;
}s;
int ch;
};
int main()
{
union Un u = {2};
printf("%d n", u.s.ch);
}

A. Compilation Error
B. 0
C. 2
D. Nothing
E. None of these
Answer» D. Nothing
9.

In the following declaration of bit-fields, the constant-expression must be __________.
struct-declarator:
declarator
type-specifier declarator opt : constant-expression

A. Nonnegative integer value
B. Any type
C. Nothing
D. Integer value
E. None of these
Answer» B. Any type
10.

In the following declaration of bit-fields, the constant-expression specifies __________.
struct-declarator:
declarator
type-specifier declarator opt : constant-expression

A. Error
B. The width of the field in bytes
C. Nothing
D. The width of the field in bits
E. None of these
Answer» E. None of these
11.

What will be the output of the following C code?
#include <stdio.h>
struct N
{
unsigned int x : 1;
unsigned int y : 1;
};
int main()
{
struct N n;
n.x = 10;
n.y = 20;
printf("%d n", n.y);
}

A. 0
B. 1
C. 10
D. 20
E. Garbage value
Answer» B. 1
12.

What will be the output of the following C code?
#include <stdio.h>
struct Stru
{
unsigned int x : 7;
unsigned int y : 2;
};
int main()
{
struct Stru s;
s.x = 110;
s.y = 2;
printf("%d n", s.x);
}

A. 7
B. 2
C. Compilation Error
D. Garbage value
E. 110
Answer» F.
13.

What will be the output of the following C code?
#include <stdio.h>
struct St
{
unsigned int c : 2;
unsigned int n : 2;
};
int main()
{
struct St s;
s.c = 13;
s.n = 10;
printf("%d n", s.n);
}

A. 10
B. 13
C. 2
D. Garbage value
E. None of these
Answer» D. Garbage value
14.

What will be the output of the following C code?
#include <stdio.h>
struct Stru
{
unsigned int ch : 2;
unsigned int n : 2;
};
int main()
{
struct Stru s;
s.ch = 3;
s.n = 1;
printf("%d n", sizeof(s));
}

A. 2
B. 4
C. Undefined behaviour
D. Garbage value
E. None of these
Answer» C. Undefined behaviour
15.

What will be the output of the following C code?
#include <stdio.h>
union N
{
struct
{
unsigned char c : 2;
unsigned int num : 2;
}M;
int c;
};
int main()
{
union N n.M = {2};
printf("%d n", n.M.c);
}

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