Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 391–400 of 1,000
Topics in C Programming
Q.391 Medium Structures & Unions
How do you access a member of a structure using a pointer?
A ptr.member
B ptr->member
C *ptr.member
D ptr*member
Correct Answer:  B. ptr->member
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. Dot (.) is for direct variables.

Test
Q.392 Medium Structures & Unions
What will be printed?
struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
A 9 bytes
B 12 bytes
C 13 bytes
D 8 bytes
Correct Answer:  B. 12 bytes
EXPLANATION

Due to memory alignment/padding: int a(4) + char b(1) + 3 padding bytes + int c(4) = 12 bytes.

Test
Q.393 Medium Structures & Unions
What is the difference between struct and typedef struct?
A No difference, both are identical
B typedef struct allows direct variable declaration without 'struct' keyword
C struct is faster than typedef struct
D typedef struct is used only in C++
Correct Answer:  B. typedef struct allows direct variable declaration without 'struct' keyword
EXPLANATION

typedef struct creates an alias, so you can declare variables directly using the alias name without repeating 'struct'.

Test
Q.394 Medium Structures & Unions
Which of the following correctly declares a pointer to a structure?
A struct emp *ptr;
B *struct emp ptr;
C struct *emp ptr;
D emp struct *ptr;
Correct Answer:  A. struct emp *ptr;
EXPLANATION

Correct syntax is 'struct typename *pointerName;'. Option A follows proper declaration syntax.

Test
Q.395 Medium Structures & Unions
What happens when you initialize a structure variable without assigning values?
A Members are automatically set to 0
B Members contain garbage values
C Compilation error occurs
D Members are set to NULL
Correct Answer:  B. Members contain garbage values
EXPLANATION

Uninitialized local structure variables contain garbage values. Global structures are automatically initialized to zero.

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

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