What is the output of this C code snippet?
#include <stdio.h> int main() { int x = 5; if (x > 3) { if (x < 10) { printf("Inside range\n"); } else { printf("Too large\n"); } } else { printf("Too small\n"); } return 0; }
Check the conditions carefully and follow the indentation to see which block runs.
The variable x is 5, which is greater than 3 and less than 10, so the first inner if condition is true. The program prints "Inside range".
Which variable name is the most readable and follows good naming conventions in C?
Think about names that clearly describe what the variable holds.
Variable names should be descriptive and meaningful. 'numberOfStudents' clearly tells what the variable represents, improving code readability.
What is the main readability problem in this C code snippet?
int main(){int a=10;int b=20;if(a>b){printf("A is bigger\n");}else{printf("B is bigger\n");}return 0;}
Look at how the code is spaced and arranged.
The code lacks proper spacing and indentation, making it difficult to follow. Adding spaces and new lines improves readability.
Which of the following C code snippets will cause a syntax error?
Remember the syntax rules for if statements in C.
Option B is missing parentheses around the condition and uses braces incorrectly, causing a syntax error.
Consider this C code. How many lines will it print?
#include <stdio.h> int main() { for (int i = 0; i < 10; i++) { if (i % 2 == 0) { printf("%d\n", i); } } return 0; }
Count how many numbers from 0 to 9 are even.
The loop prints numbers from 0 to 9 that are even. These are 0, 2, 4, 6, 8 — a total of 5 lines.