Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

309 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 221–230 of 309
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.221 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.222 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.223 Medium C Programming
What is the output of: int a = 10, b = 20; int temp = a; a = b; b = temp; printf("%d %d", a, b);?
A 10 20
B 20 10
C 20 20
D 10 10
Correct Answer:  B. 20 10
EXPLANATION

This is a swap operation. Initially a=10, b=20. After temp=a (temp=10), a=b (a=20), b=temp (b=10). Output: 20 10.

Take Test
Q.224 Medium C Programming
Which function is used to allocate memory dynamically in C?
A allocate()
B malloc()
C new()
D create()
Correct Answer:  B. malloc()
EXPLANATION

malloc() (memory allocation) is used to dynamically allocate memory on the heap in C. It requires #include <stdlib.h>. new() is used in C++, not C.

Take Test
Q.225 Medium C Programming
What will be the output of: int x = 5; int y = ++x; printf("%d %d", x, y);?
A 5 5
B 6 6
C 5 6
D 6 5
Correct Answer:  B. 6 6
EXPLANATION

The pre-increment operator (++x) increments x first, then assigns it. So x becomes 6, and y is assigned 6. Output: 6 6.

Take Test
Q.226 Medium C Programming
Which loop in C does NOT check the condition before executing the loop body?
A for loop
B while loop
C do-while loop
D foreach loop
Correct Answer:  C. do-while loop
EXPLANATION

The do-while loop executes the loop body at least once before checking the condition. Other loops check the condition before execution. Syntax: do { } while(condition);

Take Test
Q.227 Medium C Programming
What will be the output of: int x = 5; x += 3; printf("%d", x);?
A 5
B 8
C 3
D 53
Correct Answer:  B. 8
EXPLANATION

The operator += means x = x + 3. So x = 5 + 3 = 8. The printf statement outputs 8.

Take Test
Q.228 Easy C Programming
What is the purpose of the return statement in a C function?
A To exit the program
B To return a value to the caller and exit the function
C To declare variables
D To create a loop
Correct Answer:  B. To return a value to the caller and exit the function
EXPLANATION

The return statement is used to exit a function and return a value (if any) to the calling function. If the function has return type void, no value is returned.

Take Test
Q.229 Easy C Programming
Which of the following is used to declare a constant in C?
A constant int x = 5;
B const int x = 5;
C final int x = 5;
D immutable int x = 5;
Correct Answer:  B. const int x = 5;
EXPLANATION

In C, the 'const' keyword is used to declare constants. Once a const variable is initialized, its value cannot be changed. Options A, C, and D are not valid C syntax.

Take Test
Q.230 Easy C Programming
What will be the output of: int a = 10; int b = 20; int c = a + b; printf("%d", c);?
A 10
B 30
C 20
D Error
Correct Answer:  B. 30
EXPLANATION

Variable 'a' is initialized to 10, 'b' is initialized to 20. When c = a + b, c becomes 10 + 20 = 30. Therefore, printf outputs 30.

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