C Institute
CLA-11-03
CLA - C Certified Associate Programmer
Exam Version: 6.0
Questions & Answers PDF
(Demo Version - Limited Content)
For More Information - Visit link below:
https://p2pexam.com/cla-11-03
, Question 1. (Single Select)
Assume that ints and floats are 32-bit wide.
What happens if you try to compile and run this program?
#include <stdio.h>
union uni {
float f, g;
int i, j;
};
int main (int argc, char *argv[]) {
union uni u;
printf ("%ld", sizeof (u) ) ;
return 0;
}
Choose the right answer:
A: The program outputs 16
B: The program outputs 8
C: Compilation fails
D: The program outputs 4
E: The program outputs 24
Answer: D
Explanation:
This is because when you initialize u with some values, only one member of u will be as-signed a value at a
time, and the rest will remain uninitialized. Therefore, when you print sizeof(u), it will show the size of the
largest member, which is f in this case. Since f is 4 bytes long, sizeof(u) will be 4 bytes as well.
If you want to learn more about unions in C programming, you can check out these re-sources:
- C Unions - GeeksforGeeks
https://p2pexam.com/cla-11-03 Page 2 of 8
CLA-11-03
CLA - C Certified Associate Programmer
Exam Version: 6.0
Questions & Answers PDF
(Demo Version - Limited Content)
For More Information - Visit link below:
https://p2pexam.com/cla-11-03
, Question 1. (Single Select)
Assume that ints and floats are 32-bit wide.
What happens if you try to compile and run this program?
#include <stdio.h>
union uni {
float f, g;
int i, j;
};
int main (int argc, char *argv[]) {
union uni u;
printf ("%ld", sizeof (u) ) ;
return 0;
}
Choose the right answer:
A: The program outputs 16
B: The program outputs 8
C: Compilation fails
D: The program outputs 4
E: The program outputs 24
Answer: D
Explanation:
This is because when you initialize u with some values, only one member of u will be as-signed a value at a
time, and the rest will remain uninitialized. Therefore, when you print sizeof(u), it will show the size of the
largest member, which is f in this case. Since f is 4 bytes long, sizeof(u) will be 4 bytes as well.
If you want to learn more about unions in C programming, you can check out these re-sources:
- C Unions - GeeksforGeeks
https://p2pexam.com/cla-11-03 Page 2 of 8