This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Bit-fields – 2”.
Pre-requisite for C Bit-fields MCQ set: Video Tutorial on C Bit-fields.
1. What will be the output of the following C code?
#include <stdio.h>
struct p
{
char x : 2;
int y : 2;
};
int main()
{
struct p p;
p.x = 2;
p.y = 1;
p.x = p.x & p.y;
printf("%d\n", p.x);
}
a) 0
b) Compile time error
c) Undefined behaviour
d) Depends on the standard
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct p
{
unsigned char x : 2;
unsigned int y : 2;
};
int x;
};
int main()
{
union u u;
u.p.x = 2;
printf("%d\n", u.p.x);
}
a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 2
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u;
u.p.x = 2;
printf("%d\n", u.p.x);
}
a) Compile time error
b) 2
c) Undefined behaviour
d) Depends on the standard
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u.p.x = 2;
printf("%d\n", u.p.x);
}
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u = {2};
printf("%d\n", u.p.x);
}
a) Compile time error
b) 2
c) Depends on the standard
d) None of the mentioned
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u.p = {2};
printf("%d\n", u.p.x);
}
a) Compile time error
b) 2
c) Undefined behaviour
d) None of the mentioned
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 1;
printf("%d\n", sizeof(p));
}
a) Compile time error
b) Depends on the compiler
c) 2
d) 4
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 4;
printf("%d\n", p.y);
}
a) 0
b) 4
c) Depends on the compiler
d) 2
View Answer
Explanation: None.
9. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 7;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 110;
p.y = 2;
printf("%d\n", p.x);
}
a) Compile time error
b) 110
c) Depends on the standard
d) None of the mentioned
View Answer
Explanation: None.
10. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 1;
unsigned int y : 1;
};
int main()
{
struct p p;
p.x = 1;
p.y = 2;
printf("%d\n", p.y);
}
a) 1
b) 2
c) 0
d) Depends on the compiler
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Buy Computer Science Books
- Apply for C Internship
- Practice BCA MCQs
- Watch Advanced C Programming Videos