Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 111–120 of 303
Topics in C Programming
What will be the output of sizeof() for the following union? union data { int a; float b; double c; }
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

The size of a union is the size of its largest member. Here, double (8 bytes) is the largest, so sizeof(union data) = 8 bytes.

Take Test
Which of the following is a key difference between struct and union in C?
A Struct members share memory while union members don't
B Union members share memory while struct members don't
C Both allocate same memory to all members
D Union cannot have more than 2 members
Correct Answer:  B. Union members share memory while struct members don't
EXPLANATION

In unions, all members share the same memory location, so only one member can hold a value at a time. In structs, each member has its own memory space.

Take Test
Can we pass a structure variable to a function in C?
A No, structures cannot be passed
B Yes, by value only
C Yes, by value or by reference using pointers
D Only through global variables
Correct Answer:  C. Yes, by value or by reference using pointers
EXPLANATION

Structures can be passed by value (copy of structure) or by reference (using pointers to structure).

Take Test
What is the size of the following structure?
struct point { int x; int y; float z; };
A 9 bytes
B 12 bytes
C 8 bytes
D 16 bytes
Correct Answer:  B. 12 bytes
EXPLANATION

int x = 4 bytes, int y = 4 bytes, float z = 4 bytes. Total = 12 bytes (no padding in this case on most systems).

Take Test
Which keyword is used to define a structure in C?
A class
B struct
C record
D object
Correct Answer:  B. struct
EXPLANATION

The 'struct' keyword is used to define structures in C. 'class' is used in C++ and Java.

Take Test
What will be the output of sizeof(union test) if union has members: int a, char b, float c?
A 4 bytes
B 7 bytes
C 9 bytes
D 11 bytes
Correct Answer:  A. 4 bytes
EXPLANATION

Union size equals the size of its largest member. Here, both int and float are 4 bytes (largest), so sizeof(union test) = 4 bytes.

Take Test
What is the primary difference between a structure and a union in C?
A Structure allocates memory for all members, union shares memory among members
B Union allocates memory for all members, structure shares memory
C Both allocate same memory but structure is faster
D There is no difference, they are synonyms
Correct Answer:  A. Structure allocates memory for all members, union shares memory among members
EXPLANATION

In structures, each member gets its own memory space. In unions, all members share the same memory location, so only one member can hold a value at a time.

Take Test
Q.118 Easy Pointers
What is the primary issue with this code?
int *p;
*p = 10;
A Syntax error
B Pointer p is uninitialized and points to garbage memory
C The value 10 cannot be assigned through a pointer
D Missing return statement
Correct Answer:  B. Pointer p is uninitialized and points to garbage memory
EXPLANATION

p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.

Take Test
Q.119 Easy Pointers
Consider the declaration: const int *p; and int * const q;
Which statement is TRUE?
A Both p and q cannot be modified
B p points to a constant integer; q is a constant pointer to integer
C Both declarations are identical
D Both p and q can be modified freely
Correct Answer:  B. p points to a constant integer; q is a constant pointer to integer
EXPLANATION

const int *p means p can change but the data it points to cannot. int * const q means q cannot change but the data it points to can be modified.

Take Test
Q.120 Easy Pointers
What is the output of the following code?
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
A 10
B Address of x
C Address of p
D Garbage value
Correct Answer:  A. 10
EXPLANATION

q is a pointer to pointer p. **q dereferences q twice: first to get p, then to get the value of x which is 10.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips