Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
What is the output of the following code?
#include
int main() {
int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));
return 0;
}
#include
int main() {
int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));
return 0;
}
Correct Answer:
B. 20
EXPLANATION
arr + 1 points to the second element. Dereferencing with * gives the value 20.
Which keyword is used to create a variable that cannot be modified after initialization?
Correct Answer:
B. const
EXPLANATION
The 'const' keyword creates a constant variable that cannot be modified after initialization. The compiler enforces this at compile time.
Which escape sequence represents a tab character in C?
Correct Answer:
A. \t
EXPLANATION
\t is the escape sequence for a tab character. \n is for newline, \s is invalid in C.
What is the purpose of the main() function in C?
Correct Answer:
C. Entry point of program execution
EXPLANATION
The main() function is the entry point where program execution begins. Every C program must have a main() function.
What is the output of: printf("%d", 5 + 3 * 2)?
Correct Answer:
B. 11
EXPLANATION
Following operator precedence, multiplication (*) has higher precedence than addition (+). So 3*2=6, then 5+6=11.
What does the following code snippet output?
#include
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
#include
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
Correct Answer:
A. 5
EXPLANATION
x++ is post-increment. The value 5 is printed first, then x is incremented to 6.
Which of the following is the correct syntax to declare a variable in C?
Correct Answer:
A. int x;
EXPLANATION
In C, variable declaration requires a semicolon at the end. The syntax is 'data_type variable_name;'