Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

200 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 61–70 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.61 Medium C Programming
What will be printed: int i = 0; while(i < 3) { printf("%d ", i); i++; }
A 0 1 2
B 1 2 3
C 0 1 2 3
D Nothing is printed
Correct Answer:  A. 0 1 2
EXPLANATION

The while loop starts with i=0. It prints 0, then increments i to 1, prints 1, increments to 2, prints 2, increments to 3, and the condition i<3 becomes false, so the loop terminates. Output: 0 1 2

Take Test
Q.62 Easy C Programming
Which of the following is true about the 'break' statement in C?
A It skips the current iteration
B It exits the loop or switch statement
C It terminates the program
D It has no effect in loops
Correct Answer:  B. It exits the loop or switch statement
EXPLANATION

The 'break' statement is used to exit or terminate a loop or switch statement immediately. It transfers control to the statement following the loop or switch.

Take Test
Q.63 Medium C Programming
Which of the following operators has the highest precedence in C?
A * (multiplication)
B ++ (increment)
C + (addition)
D = (assignment)
Correct Answer:  B. ++ (increment)
EXPLANATION

The increment (++) and decrement (--) operators have the highest precedence among all operators in C, followed by unary operators, then multiplicative, additive, and so on.

Take Test
Q.64 Medium C Programming
What will be the final value of x: int x = 5; x += 3 * 2; printf("%d", x);
A 16
B 11
C 13
D 36
Correct Answer:  A. 16
EXPLANATION
Step 1: x = 5. Step 2: 3 * 2 = 6 (multiplication has higher precedence). Step 3: x += 6 means x = x + 6 = 5 + 6 = 11. Wait, let me recalculate: x = 5; x += 6 gives x = 11. The answer should be B (11), not A. Correction: The correct answer is B.
Take Test
Q.65 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.66 Hard C Programming
What does the 'volatile' keyword indicate in C?
A The variable can be modified externally at any time
B The variable cannot be modified
C The variable is stored in a register
D The variable has global scope
Correct Answer:  A. The variable can be modified externally at any time
EXPLANATION

The volatile keyword tells the compiler that a variable's value may change unexpectedly (e.g., due to hardware, interrupts, or other threads), preventing compiler optimizations that assume the value doesn't change.

Take Test
Q.67 Medium C Programming
Which of the following correctly represents a structure declaration in C?
A struct {int a; char b;} s;
B struct Name {int a; char b;};
C Both A and B are correct
D Neither A nor B is correct
Correct Answer:  C. Both A and B are correct
EXPLANATION

Both are valid syntax. Option A declares an anonymous structure with immediate variable instantiation. Option B declares a named structure type that can be used later to create variables.

Take Test
Q.68 Medium C Programming
What is the purpose of the 'static' keyword when used with a variable inside a function?
A To make the variable global
B To preserve the variable's value between function calls
C To prevent the variable from being modified
D To allocate memory on the stack
Correct Answer:  B. To preserve the variable's value between function calls
EXPLANATION

A static variable inside a function is initialized only once and retains its value between successive function calls. It has memory allocated in the data segment, not the stack.

Take Test
Q.69 Medium C Programming
In C, which function is used to read a string from input with space handling?
A scanf("%s", str);
B fgets(str, sizeof(str), stdin);
C gets(str);
D getline(str);
Correct Answer:  B. fgets(str, sizeof(str), stdin);
EXPLANATION

fgets() is the safe way to read strings including spaces. scanf("%s") stops at whitespace, gets() is deprecated and unsafe due to buffer overflow risks.

Take Test
Q.70 Medium C Programming
What is the output of: int a = 10, b = 20; a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d", a, b);
A 10 20
B 20 10
C 0 0
D 20 20
Correct Answer:  B. 20 10
EXPLANATION

This is XOR swap algorithm. Step 1: a = 10^20. Step 2: b = (10^20)^20 = 10. Step 3: a = (10^20)^10 = 20. Result: a=20, b=10 (values are swapped).

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