Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
150 Questions 5 Topics Take Test
Advertisement
Showing 21–30 of 150 questions
Q.21 Medium C Programming
What will be the memory size of the following struct?
struct Point { int x; char c; int y; }
A 9 bytes
B 10 bytes
C 12 bytes
D 16 bytes
Correct Answer:  C. 12 bytes
Explanation:

Due to memory alignment/padding: int x (4 bytes), char c (1 byte) + 3 bytes padding, int y (4 bytes) = 12 bytes total. The compiler adds padding to align data members to their natural boundaries for efficient memory access.

Take Test
Q.22 Medium C Programming
What is the correct way to initialize an array of 5 integers with all elements as 0?
A int arr[5] = {};
B int arr[5] = {0};
C Both A and B
D int arr[5] = {0, 0, 0, 0, 0};
Correct Answer:  C. Both A and B
Explanation:

Both {} and {0} will initialize all array elements to 0. When you provide fewer initializers than array size, remaining elements are automatically set to 0.

Take Test
Q.23 Medium C Programming
Which of the following correctly declares a pointer to a pointer?
A int *ptr;
B int **ptr;
C int &ptr;
D int ***ptr;
Correct Answer:  B. int **ptr;
Explanation:

A pointer to a pointer is declared using two asterisks (). int ptr declares a pointer that points to another pointer that points to an integer.

Take Test
Q.24 Medium C Programming
What is the scope of a variable declared inside a function in C?
A Global scope
B Local/Function scope
C Static scope
D External scope
Correct Answer:  B. Local/Function scope
Explanation:

Variables declared inside a function have local scope (also called function scope). They are only accessible within that function and are destroyed when the function returns.

Take Test
Q.25 Medium C Programming
What is the difference between calloc() and malloc() in C?
A calloc() initializes memory to 0, malloc() does not
B malloc() is faster than calloc()
C calloc() takes two arguments, malloc() takes one
D All of the above
Correct Answer:  D. All of the above
Explanation:

calloc() allocates memory and initializes all bytes to 0, takes (number of elements, size of each element). malloc() just allocates memory without initialization and takes total size. calloc() is slightly slower due to initialization.

Take Test
Advertisement
Q.26 Medium C Programming
What is the correct syntax to open a file in C?
A FILE *fp = fopen("file.txt", "r");
B FILE fp = open("file.txt", "r");
C fopen *fp = FILE("file.txt", "r");
D FILE fp = fopen("file.txt");
Correct Answer:  A. FILE *fp = fopen("file.txt", "r");
Explanation:

The correct syntax is FILE *fp = fopen("filename", "mode");. fopen() returns a pointer to a FILE structure, and the mode string specifies how to open the file ("r" for read, "w" for write, etc.).

Take Test
Q.27 Medium C Programming
Consider the following code:
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
What is the value of *(ptr + 2)?
A 1
B 2
C 3
D 4
Correct Answer:  C. 3
Explanation:

ptr points to arr[0]. ptr + 2 points to arr[2]. *(ptr + 2) dereferences to get the value at arr[2], which is 3. Pointer arithmetic moves by the size of the data type (integers).

Take Test
Q.28 Medium C Programming
What is the output of the following code?
for(int i = 1; i
A 1 2 3
B 1 3
C 2 3
D 1
Correct Answer:  B. 1 3
Explanation:

When i = 1, it prints 1. When i = 2, continue skips the printf() and moves to the next iteration. When i = 3, it prints 3. Output: 1 3

Take Test
Q.29 Medium C Programming
What is the output of: int x = 10; printf("%d", x++); printf("%d", x);
A 1010
B 1011
C 910
D 111
Correct Answer:  B. 1011
Explanation:

x++ is post-increment. First printf uses current value (10), then x is incremented. Second printf uses new value (11). Output: 1011

Take Test
Q.30 Medium C Programming
Which of the following correctly declares a pointer to an integer?
A int *ptr;
B *int ptr;
C ptr *int;
D int ptr*;
Correct Answer:  A. int *ptr;
Explanation:

The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates that ptr is a pointer. The placement of * before the variable name is crucial.

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