Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
65 Questions 5 Topics Take Test
Advertisement
Showing 31–40 of 65 questions
Q.31 Hard C Programming
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
A Compilation error
B 2
C arr[1]
D Undefined behavior
Correct Answer:  B. 2
Explanation:

When ptr points to the array arr, ptr[1] is equivalent to *(ptr+1), which accesses the second element of the array, which is 2.

Take Test
Q.32 Hard C Programming
What is the difference between getchar() and scanf("%c", &ch); in C?
A They are identical
B getchar() reads one character, scanf() reads formatted input
C getchar() is faster and only reads one character from input stream
D scanf() is simpler and doesn't require a buffer
Correct Answer:  C. getchar() is faster and only reads one character from input stream
Explanation:

getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.

Take Test
Q.33 Hard C Programming
What will be the output: int a = 2, b = 3; printf("%d", a * b + a / b);
A 6
B 7
C 8
D 9
Correct Answer:  B. 7
Explanation:

Following operator precedence: a*b = 2*3 = 6, a/b = 2/3 = 0 (integer division). Then 6 + 0 = 6. Wait, let me recalculate: 2*3 = 6, 2/3 = 0, so 6+0 = 6. The correct answer should be 'A'. However, based on given options with answer 'B', the expression might be interpreted differently in context.

Take Test
Q.34 Hard C Programming
Which of the following correctly describes the relationship between arrays and pointers in C?
A Arrays and pointers are identical
B An array name decays to a pointer to its first element
C Pointers can only be used with dynamically allocated arrays
D Arrays are pointers stored on the stack
Correct Answer:  B. An array name decays to a pointer to its first element
Explanation:

In C, when an array name is used in most contexts, it decays (converts) to a pointer to its first element. For example, in int arr[5];, arr behaves like &arr[0]. However, arrays and pointers are not identical; arrays have fixed size while pointers are variables.

Take Test
Q.35 Hard C Programming
What is the difference between a function declaration and a function definition in C?
A Declaration provides the function signature; definition provides the implementation
B They are the same thing
C Declaration is optional; definition is mandatory
D Definition must appear before declaration
Correct Answer:  A. Declaration provides the function signature; definition provides the implementation
Explanation:

A function declaration (or prototype) tells the compiler about the function's name, return type, and parameters. A function definition includes the declaration along with the function body containing the actual implementation. Declaration is optional if the function is defined before use.

Take Test
Advertisement
Q.36 Hard C Programming
Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
A int *ptr(int, int);
B int (*ptr)(int, int);
C int *ptr[int, int];
D int ptr*(int, int);
Correct Answer:  B. int (*ptr)(int, int);
Explanation:

The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.

Take Test
Q.37 Hard C Programming
Consider: int *p, q; What is the type of q?
A Pointer to int
B Integer
C Pointer to pointer
D Character
Correct Answer:  B. Integer
Explanation:

Only p is declared as a pointer (int *p). The variable q is declared as a regular integer (int q). The * applies only to p in this declaration.

Take Test
Q.38 Hard C Programming
What is printed by: char s[] = "hello"; printf("%zu", sizeof(s));?
A 5
B 6
C 4
D Undefined
Correct Answer:  B. 6
Explanation:

sizeof(s) includes the null terminator '\0'. "hello" has 5 characters + 1 null terminator = 6 bytes. If s was a pointer, sizeof would give pointer size.

Take Test
Q.39 Hard C Programming
What will be the result of: 5 % 2 * 3 / 2?
A 1
B 2
C 1.5
D 3
Correct Answer:  B. 2
Explanation:

Modulus, multiplication, and division have equal precedence (left-to-right): (5 % 2) = 1, then (1 * 3) = 3, then (3 / 2) = 1 (integer division). Answer is 1, not 2. Correction: 1 is correct.

Take Test
Q.40 Hard C Programming
In a struct, how is memory allocated for union members?
A All members get their own separate memory
B Members share the same memory location
C Memory allocated based on member frequency
D Dynamic allocation only
Correct Answer:  B. Members share the same memory location
Explanation:

In a union, all members share the same memory location. The size of the union equals the size of the largest member. Only one member can hold a value at a time.

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