Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
150 Questions 5 Topics Take Test
Advertisement
Showing 81–90 of 150 questions
Q.81 Medium C Programming
Which of the following is a correct way to initialize a pointer to NULL?
A int *ptr = 0;
B int *ptr = NULL;
C int *ptr = (void*)0;
D All of the above
Correct Answer:  D. All of the above
Explanation:

All three methods are correct ways to initialize a pointer to NULL. 0, NULL, and (void*)0 all represent a null pointer. NULL is typically a macro defined as 0 or ((void*)0) in the standard library.

Take Test
Q.82 Medium C Programming
What is the output of the expression: 10 / 3 * 3 in C?
A 10
B 9
C 3.33
D Cannot be determined
Correct Answer:  B. 9
Explanation:

Division and multiplication have the same precedence and are evaluated left-to-right. Step 1: 10 / 3 = 3 (integer division). Step 2: 3 * 3 = 9. Therefore, the result is 9.

Take Test
Q.83 Medium C Programming
What is the correct syntax to pass a 2D array to a function in C?
A func(int arr[][])
B func(int arr[rows][cols])
C func(int arr[][cols])
D func(int **arr)
Correct Answer:  C. func(int arr[][cols])
Explanation:

When passing a 2D array to a function, the number of columns must be specified, but the number of rows is optional. Option C is the standard correct syntax.

Take Test
Q.84 Medium C Programming
What will be printed by: int x = 5; printf("%d", ++x + x++);?
A 11
B 12
C 13
D 14
Correct Answer:  B. 12
Explanation:

++x increments x to 6 (pre-increment), then x++ returns 6 and increments x to 7. So: 6 + 6 = 12. Post-increment returns the old value.

Take Test
Q.85 Medium C Programming
Which of the following correctly uses the ternary operator?
A x = (a > b) : a : b;
B x = (a > b) ? a : b;
C x = a > b ? a : b
D x = (a > b) -> a : b;
Correct Answer:  B. x = (a > b) ? a : b;
Explanation:

The ternary operator syntax is: condition ? value_if_true : value_if_false. Option B is the only correctly formatted statement.

Take Test
Advertisement
Q.86 Medium C Programming
What is the purpose of the const keyword when used with a pointer?
A To make the pointer variable unchangeable
B To make the pointed data unchangeable
C Both A and B depending on placement
D To allocate memory in the constant segment
Correct Answer:  C. Both A and B depending on placement
Explanation:

const int *ptr makes the data constant (const int * ptr). int * const ptr makes the pointer constant. The position of const matters.

Take Test
Q.87 Medium C Programming
What is the return type of malloc() function?
A int*
B char*
C void*
D size_t
Correct Answer:  C. void*
Explanation:

malloc() returns a void pointer (void*), which can be cast to any data type pointer as needed by the programmer.

Take Test
Q.88 Medium C Programming
In the expression: int arr[10]; what is arr[5]?
A A pointer to the 5th element
B The value at memory address arr + 5
C Both A and B are equivalent
D An integer value between 0-10
Correct Answer:  C. Both A and B are equivalent
Explanation:

arr[5] accesses the element at index 5, which is at memory address (arr + 5). Array name arr acts as a pointer to the first element.

Take Test
Q.89 Medium C Programming
What is the output of: int a = 10, b = 20; int *p = &a, *q = &b; printf("%d", *p + *q);?
A 10
B 20
C 30
D Error
Correct Answer:  C. 30
Explanation:

*p dereferences to a (10) and *q dereferences to b (20). Adding them: 10 + 20 = 30. Pointer arithmetic is used correctly here.

Take Test
Q.90 Medium C Programming
What is the output of: int x = 5; int y = ++x; ?
A x = 5, y = 5
B x = 6, y = 6
C x = 6, y = 5
D x = 5, y = 6
Correct Answer:  B. x = 6, y = 6
Explanation:

The pre-increment operator ++x increments x first (from 5 to 6), then assigns the new value to y. So x = 6 and y = 6.

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