✏️ Explanatory Question
Program Objective: Write a C program to display the message
"Hello World" on the console.
Algorithm
- Start the program.
- Include the
header file. - Create the
main()function. - Use the
printf()function to display Hello World. - Return
0to indicate successful execution. - End the program.
C Program
#include
int main()
{
printf("Hello World");
return 0;
}
Output
Hello World
Program Explanation
| Statement | Explanation |
|---|---|
#include |
Includes the Standard Input/Output header file, which provides the printf() function. |
int main() |
The main() function is the entry point where program execution begins. |
printf("Hello World"); |
Displays the text Hello World on the screen. |
return 0; |
Ends the program and returns a success status to the operating system. |
Program Flow
Start
│
▼
Include stdio.h
│
▼
main()
│
▼
printf("Hello World")
│
▼
return 0
│
▼
End
Key Points
Important Notes
printf()is used to display output on the screen.must be included to useprintf().- Every standard C program begins execution from the
main()function. return 0;indicates that the program executed successfully.
Common Mistakes
Avoid These Mistakes
- Forgetting to include
. - Misspelling
printf(). - Missing the semicolon (
;) after theprintf()statement. - Using
void main()instead ofint main()in standard C. - Forgetting the double quotation marks around the string.
Best Practices
- Always write
int main()for standard C programs. - Indent the code properly for better readability.
- Use meaningful comments when necessary.
- Return
0after successful execution.
Prerequisites
Before Learning This Program
- Basic understanding of C program structure.
- Knowledge of the
main()function. - Basic understanding of the
printf()function. - Familiarity with the
header file.
Interview Questions
- Why is
included in this program? - What is the purpose of the
printf()function? - Why does the
main()function return0? - Can this program run without the
main()function? - What happens if the semicolon after
printf()is omitted?
Key Takeaway
The Hello World program is the simplest C program and is often
the first step in learning C programming. It introduces the basic program
structure, the main() function, the
header file, and the printf() function used to display output on
the screen.