Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
150 Questions 5 Topics Take Test
Advertisement
Showing 41–50 of 150 questions
Q.41 Medium C Programming
In C, what does the scanf() function do?
A Displays output to the screen
B Reads input from standard input (keyboard)
C Creates a new variable
D Allocates memory
Correct Answer:  B. Reads input from standard input (keyboard)
Explanation:

scanf() reads formatted input from the standard input device (usually keyboard). printf() displays output. Both require #include <stdio.h>.

Take Test
Q.42 Medium C Programming
What will be the output of: for(int i = 0; i < 3; i++) { printf("%d ", i); }?
A 0 1 2
B 1 2 3
C 0 1 2 3
D 3 2 1
Correct Answer:  A. 0 1 2
Explanation:

Loop runs with i=0,1,2. When i=3, condition i<3 becomes false and loop terminates. Output: 0 1 2 (with spaces).

Take Test
Q.43 Medium C Programming
Which of the following is the correct way to define a function that takes no parameters and returns no value?
A void function() { }
B null function() { }
C empty function() { }
D void function(void) { }
Correct Answer:  A. void function() { }
Explanation:

In C, void function() { } is correct. In some contexts, void function(void) { } is more explicit. Options B and C use invalid keywords for this purpose.

Take Test
Q.44 Medium C Programming
What is the output of the following program: int x = 5; if(x > 3) printf("Greater"); else printf("Smaller");?
A Smaller
B Greater
C 5
D Error
Correct Answer:  B. Greater
Explanation:

x=5 is greater than 3, so the condition (x > 3) evaluates to true. The if block executes, printing 'Greater'.

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

malloc() returns a void pointer (void*) which can be cast to any pointer type. It returns NULL if memory allocation fails.

Take Test
Advertisement
Q.46 Medium C Programming
Which function is used to release dynamically allocated memory in C?
A delete()
B free()
C release()
D dealloc()
Correct Answer:  B. free()
Explanation:

The free() function deallocates memory that was previously allocated using malloc(), calloc(), or realloc(). delete() is used in C++.

Take Test
Q.47 Medium C Programming
What is the difference between calloc() and malloc()?
A calloc() initializes memory to zero, 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(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.

Take Test
Q.48 Medium C Programming
Which of the following is used to comment multiple lines in C?
A // comment
B /* comment */
C # comment
D -- comment
Correct Answer:  B. /* comment */
Explanation:

/* */ is used for multi-line comments in C. // is used for single-line comments and was introduced in C99.

Take Test
Q.49 Medium C Programming
What will be the output of: float x = 5/2; printf("%f", x);
A 2.500000
B 2.000000
C 2.5
D Compilation Error
Correct Answer:  B. 2.000000
Explanation:

Since both 5 and 2 are integers, integer division occurs (5/2 = 2). The result 2 is then converted to float as 2.000000.

Take Test
Q.50 Medium C Programming
How are structures different from unions in C?
A Structures allocate separate memory for each member, unions share memory
B Unions allocate separate memory for each member, structures share memory
C There is no difference
D Structures are faster than unions
Correct Answer:  A. Structures allocate separate memory for each member, unions share memory
Explanation:

In structures, each member has its own memory location. In unions, all members share the same memory location, so only one 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