C Hello World Program
C Hello World Program
A classroom’s first practice program needs one readable greeting line without any numeric calculations.
puts writes a valid terminated string and then appends a newline. printf gives explicit control over formatting and whether a newline is included.
Before this exercise, review storing values and reading and checking input. The worked program below applies those ideas to this specific problem.
Explain
Explain why greeting program uses this sequence of operations.
Trace
Trace the sample values and predict the printed result.
Apply
Use Hill School as the destination in the greeting.
Greeting Program: follow the data
Given data
A classroom’s first practice program needs one readable greeting line without any numeric calculations.
Rule
puts writes a valid terminated string and then appends a newline. printf gives explicit control over formatting and whether a newline is included.
Observed result
Hello, River School!
Understand the operation
The stdio.h declaration tells the compiler how puts is called. Its string argument is text data; the function appends the line ending.
Use printf("%s\n", message) when the same output must be described through a formatting contract. Do not pass untrusted text as the format itself.
Read the complete C program
The input values are written into this complete C17 example so the calculation can be reproduced without an unavailable service. Change the named data, rebuild and compare the actual output with your prediction.
C17 · complete program
#include <stdio.h>
int main(void) {
puts("Hello, River School!");
return 0;
}
Expected output
Hello, River School!
Run in C compiler →Follow the values through the code
C17 · code used in this explanation
#include <stdio.h>
int main(void) {
puts("Hello, River School!");
return 0;
}
main passes the school greeting string to puts.
puts writes its characters and then a newline; return zero terminates the program successfully.
Follow the worked calculation
Start with the sample
main passes the school greeting string to puts.
Apply the rule
puts writes its characters and then a newline; return zero terminates the program successfully.
Check the result
Hello, River School!
Hello, River School!
Try a small variation
C17 · code used in this explanation
#include <stdio.h>
int main(void) {
puts("Hello, River School!");
return 0;
}
Use Hill School as the destination in the greeting.
Worked answer
Changing only the literal text changes the visible greeting. The newline remains supplied by puts rather than a manually included escape.
C17 · complete program
#include <stdio.h>
int main(void) {
puts("Hello, Hill School!");
return 0;
}
Expected output
Hello, Hill School!
Run in C compiler →Recognize the important boundaries
A printf format built directly from user-controlled text can interpret unintended conversions. Use a fixed format and supply the text as an argument.
Standard output can fail; a robust application should handle the return values required by its output-delivery contract.
Check your understanding
Choose the answer, then compare the reasoning for every option.
Use the idea independently
puts writes a valid terminated string and then appends a newline. printf gives explicit control over formatting and whether a newline is included.
Continue with source and executable basics.
Language reference: WG14 C11 committee draft. These examples use the C17-compatible subset of the explained language features.
Reaching the recap and completing the quizzes are separate milestones.