Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 111–120 of 291
Topics in C Programming
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).

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).

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.

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.

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.

Test
Q.116 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.

Test
Q.117 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.

Test
Q.118 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.

Test
Q.119 Easy Pointers
What happens with: int arr[10]; int *p = arr; *p = 5; printf("%d", arr[0]);?
A Prints garbage
B Prints 5
C Compiler error
D Prints 10
Correct Answer:  B. Prints 5
EXPLANATION

p points to arr[0]. *p = 5 modifies arr[0]. Printing arr[0] displays 5.

Test
Q.120 Easy Pointers
What is the result of: int x = 5; int *p = &x; int *q = p; if p == q?
A 0 (false)
B 1 (true)
C Undefined
D Compiler error
Correct Answer:  B. 1 (true)
EXPLANATION

Both p and q point to same address of x, so p == q evaluates to true (1).

Test
IGET
IGET AI
Online · Exam prep assistant
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