C Program - Print Numbers 1 to 10
#include <stdio.h>
This line is a preprocessor directive that tells the compiler to include the contents of the standard input/output header file (stdio.h) in the program. This header file contains definitions and prototypes for functions like printf and scanf, which are used for input and output operations.
int main() {
This line starts the main function. The main function is the starting point of a C program and is the place where the program execution begins.
The int before main indicates that the function returns an integer value, and the empty parentheses () indicate that the function takes no arguments.
for (int i = 1; i <= 10; i++) {
This line starts a for loop. The for loop is a control flow statement that allows you to execute a block of code multiple times.
The loop starts with the initialization of variable "i" to 1.
The condition i <= 10 is checked before each iteration of the loop, if it is true, the loop continues, and the code inside the loop is executed.
The i++ is the increment part of the loop, which increments the value of i by 1 after each iteration, so that the loop eventually terminates after the 10th iteration.
printf("%d\n", i);
This line uses the printf function to print the current value of the variable "i" followed by a newline character.
The %d is a format specifier that tells printf to treat the corresponding argument as an integer and the \n is a newline character, which causes the next output to be printed on a new line.
}
This line marks the end of the for loop.
return 0;
This line tells the operating system that the program has completed successfully. The return 0; statement is used to exit the main function and return control to the operating system. The value 0 is commonly used to indicate that the program completed without any errors.
}
This line marks the end of the main function.
Image by 200 Degrees from Pixabay
Comments
Post a Comment