Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 451–460 of 490
Topics in C Programming
Q.451 Medium Basics & Syntax
What is the output of this code?
#include
int main() {
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
A 5 10
B 10 5
C 0 0
D 10 10
Correct Answer:  B. 10 5
EXPLANATION

This is a classic XOR swap algorithm. After three XOR operations, a and b exchange their values. Result: a=10, b=5.

Test
Q.452 Medium Basics & Syntax
What will be printed by the following code?
#include
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
A 3 3
B 2 4
C 4 3
D 3 4
Correct Answer:  A. 3 3
EXPLANATION

*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.

Test
Q.453 Medium Basics & Syntax
Consider the following code:
int x = 5;
int *ptr = &x;
int **pptr = &ptr;
printf("%d", **pptr);
What is the output?
A 5
B Address of x
C Address of ptr
D Compilation Error
Correct Answer:  A. 5
EXPLANATION

pptr is a pointer to pointer. **pptr dereferences twice: first to get ptr, then to get x's value which is 5.

Test
Q.454 Medium Basics & Syntax
Which of the following about register variables is TRUE?
A They must be initialized
B They are faster to access than normal variables
C They cannot be pointers
D They are stored in RAM
Correct Answer:  B. They are faster to access than normal variables
EXPLANATION

register keyword suggests the compiler to store the variable in CPU register for faster access. Modern compilers often ignore this hint. You cannot take address of register variables.

Test
Q.455 Medium Basics & Syntax
What does the 'volatile' keyword in C indicate?
A Variable value can change unexpectedly
B Variable is constant
C Variable is local
D Variable must be initialized
Correct Answer:  A. Variable value can change unexpectedly
EXPLANATION

volatile tells the compiler that a variable's value can change unexpectedly (e.g., in hardware registers or interrupt handlers), so it should not optimize away repeated reads.

Test
Q.456 Medium Basics & Syntax
What is the output of: printf("%d %d", 10 % 3, 10 / 3);
A 3 3
B 1 3
C 3 1
D 10 10
Correct Answer:  B. 1 3
EXPLANATION

10 % 3 = 1 (remainder), 10 / 3 = 3 (integer division). Output is '1 3'.

Test
Q.457 Medium Basics & Syntax
Which of the following is correct about static variables in C?
A They are destroyed after function returns
B They retain their value between function calls
C They cannot be used in functions
D They are global by default
Correct Answer:  B. They retain their value between function calls
EXPLANATION

Static variables retain their value between function calls and are initialized only once. They persist for the lifetime of the program.

Test
Q.458 Medium Basics & Syntax
What will be the output of: int a = 5; int b = a < 10 ? 20 : 30; printf("%d", b);
A 5
B 10
C 20
D 30
Correct Answer:  C. 20
EXPLANATION

This is the ternary operator. Since 5 < 10 is true, b = 20. If false, b would be 30.

Test
Q.459 Medium Basics & Syntax
What is the purpose of the getchar() function in C?
A Get a string from input
B Get a single character from input
C Get a number from input
D Get a pointer from input
Correct Answer:  B. Get a single character from input
EXPLANATION

getchar() reads a single character from standard input and returns it. For strings, fgets() or scanf() is used.

Test
Q.460 Medium Basics & Syntax
In C99 and later standards, what is the purpose of 'inline' keyword?
A To declare variables inline
B A suggestion to the compiler to inline function calls
C To restrict variable scope
D To allocate memory inline
Correct Answer:  B. A suggestion to the compiler to inline function calls
EXPLANATION

'inline' is a hint to the compiler suggesting it should inline the function, though the compiler may ignore it.

Test
IGET
IGET AI
Online · Exam prep assistant
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