What is the purpose of the #include <stdio.h> line in a C program?
It tells the compiler to include the Standard Input Output library, which allows the program to use functions like printf() to display text on the screen.
Click to reveal answer
beginner
What does the int main() function represent in a C program?
It is the starting point of the program where execution begins. The program runs the code inside main() first.
Click to reveal answer
beginner
Why do we use return 0; at the end of the main() function?
It tells the operating system that the program finished successfully. Returning 0 usually means no errors happened.
Click to reveal answer
beginner
What does the printf() function do?
It prints text or variables to the screen so the user can see output from the program.
Click to reveal answer
beginner
Why do we put a semicolon ; at the end of most lines in C?
The semicolon tells the compiler that the statement is finished, like a full stop in a sentence.
Click to reveal answer
What is the correct way to start the main function in a C program?
Avoid main()
Bstart()
Cint main()
Dfunction main()
✗ Incorrect
The main function in C starts with int main() which returns an integer.
Which header file is needed to use printf()?
A<stdlib.h>
B<stdio.h>
C<string.h>
D<math.h>
✗ Incorrect
printf() is declared in the stdio.h header file.
What does return 0; mean in the main() function?
AProgram ended with no errors
BProgram has an error
CStart the program
DPause the program
✗ Incorrect
Returning 0 means the program finished successfully without errors.
Which symbol ends a statement in C?
A,
B.
C:
D;
✗ Incorrect
A semicolon ; ends a statement in C.
What will this code print?
printf("Hello, World!\n");
AHello, World!
BHello World
CHello, World!\n
DError
✗ Incorrect
It prints the text Hello, World! followed by a new line.
Explain the basic structure of a simple C program that prints text on the screen.
Think about what each part does and how they work together.
You got /5 concepts.
Why is the main() function important in every C program?
Consider what happens when you run a C program.
You got /3 concepts.
Practice
(1/5)
1. What is the purpose of the int main() function in a C program?
easy
A. It prints messages to the screen.
B. It is the starting point where the program begins execution.
C. It declares variables for the program.
D. It ends the program immediately.
Solution
Step 1: Understand the role of main()
The main() function is where the program starts running in C.
Step 2: Identify the correct purpose
It is not for declaring variables or printing messages but for starting the program.
Final Answer:
It is the starting point where the program begins execution. -> Option B
Quick Check:
Program starts at main() [OK]
Hint: Remember: C programs always start at main() [OK]
Common Mistakes:
Thinking main() prints output
Confusing main() with variable declaration
Believing main() ends the program immediately
2. Which of the following is the correct syntax to print "Hello, World!" in C?
easy
A. printf("Hello, World!");
B. printf("Hello, World!")
C. print("Hello, World!");
D. echo("Hello, World!");
Solution
Step 1: Identify the correct function for output
In C, printf is used to print text to the screen.
Step 2: Check syntax details
Each statement must end with a semicolon ;. So printf("Hello, World!"); is correct.
Final Answer:
printf("Hello, World!"); -> Option A
Quick Check:
Use printf with semicolon [OK]
Hint: Always end printf with a semicolon [OK]
Common Mistakes:
Missing semicolon at the end
Using print instead of printf
Using echo which is not C syntax
3. What will be the output of the following C program?
#include
int main() {
printf("Welcome to C programming!\n");
return 0;
}
medium
A. No output
B. Welcome to C programming!\n
C. Syntax Error
D. Welcome to C programming!
Solution
Step 1: Understand the printf statement
The string inside printf includes \n which means new line after printing.
Step 2: Predict the output
The program prints "Welcome to C programming!" followed by a new line.
Final Answer:
Welcome to C programming! -> Option D
Quick Check:
\n creates new line, output is plain text [OK]
Hint: \n means new line, not literal text [OK]
Common Mistakes:
Thinking \n prints as text
Expecting syntax error due to \n
Ignoring the return statement effect
4. Identify the error in the following C program:
#include
int main() {
printf("Hello World")
return 0;
}
medium
A. Incorrect header file included
B. Missing return type for main
C. Missing semicolon after printf statement
D. Missing main function
Solution
Step 1: Check each statement for syntax
The printf statement is missing a semicolon at the end.
Step 2: Verify other parts
The main function has correct return type and header file is correct.
Final Answer:
Missing semicolon after printf statement -> Option C
Quick Check:
Every statement ends with ; [OK]
Hint: Look for missing semicolons after statements [OK]
Common Mistakes:
Ignoring missing semicolon errors
Thinking return type is missing
Assuming wrong header file causes error
5. You want to write a C program that prints two lines: "Hello!" and "Welcome to C." Which code snippet correctly does this?
hard
A. #include
int main() {
printf("Hello!\n");
printf("Welcome to C.\n");
return 0;
}
B. #include
int main() {
printf("Hello!Welcome to C.\n");
return 0;
}
C. #include
int main() {
printf("Hello!");
printf("Welcome to C.\n");
return 0;
}
D. #include
int main() {
printf("Hello!");
printf("Welcome to C.");
return 0;
}
Solution
Step 1: Understand how to print two lines
Each line should end with a newline character \n to move to the next line.
Step 2: Check each option for correct newlines
#include
int main() {
printf("Hello!\n");
printf("Welcome to C.\n");
return 0;
} prints "Hello!" with \n and "Welcome to C." with \n, so two lines appear.
Final Answer:
Two printf statements, each ending with \n -> Option A
Quick Check:
Use \n at end of each line for separate lines [OK]
Hint: Use \n after each line to print on new lines [OK]
Common Mistakes:
Missing \n causing lines to join
Putting \n only on first line
Not returning 0 at end of main
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.