C Programming - MCQ Practice Questions
Practice free C Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
978 questions | 100% Free
In nested structures with pointers, which access method is correct? struct outer { struct inner *ptr; } *o; Accessing inner's member x:
What is the relationship between structure alignment and padding in modern C compilers?
In a structure with flexible array members, which statement is INCORRECT? struct FlexArray { int len; int arr[]; };
What is the output of the following? struct S { int a:3; int b:3; int c:3; }; printf("%zu", sizeof(struct S));
In competitive programming, when should you use union instead of struct?
What will be the output of this code? struct X { int a; float b; }; struct Y { struct X x; int c; }; printf("%zu", sizeof(struct Y));
In a structure, what does the #pragma pack(1) directive do?
If a structure contains a flexible array member, where must it be declared?
In competitive programming, when implementing a graph using adjacency lists, which data structure is most suitable?
If you have a structure with bit fields, which statement about their behavior is true?
What is the output of this complex code? struct S { char c; int i; } s; printf("%lu", sizeof(s));
In competitive programming, when you need a structure that can hold either an integer or a floating-point number (but not both simultaneously) in the most memory-efficient way, which should you use?
What will be the output of the following code? union Test { int a; char b; }; union Test t; t.a = 65; printf("%d %c", t.a, t.b);
In competitive programming for GATE/ISRO 2025, which scenario would union be preferable over structure?
Write a code snippet to read 100 bytes from a file. Which is correct?
Which of the following correctly implements appending to a file?
In a program reading a binary file of 1000 integers, fread() is called as: fread(arr, sizeof(int), 1000, fp). If only 500 integers are present, what will fread() return?
Consider using fseek() on a file opened in text mode with SEEK_END and a non-zero offset. What is the standard behavior?
A program writes data using fprintf() and later attempts to read it back. However, the read operation fails intermittently. What could be the most likely cause?
What is the purpose of using fflush() in file handling, and when is it critical to use it?