C Programming — Basics & Syntax
C language from basics to advanced placement prep
46 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 46 questions in Basics & Syntax
Q.1 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.

Take Test
Q.2 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.

Take Test
Q.3 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.

Take Test
Q.4 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.

Take Test
Q.5 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.

Take Test
Advertisement
Q.6 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'.

Take Test
Q.7 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.

Take Test
Q.8 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.

Take Test
Q.9 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.

Take Test
Q.10 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.

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