The First C Program - Hello World! : Behind the code
This code will print Hello World! as output.
1. Preprocessor macros
# directive is for C preprocessor. #include simply looks for file stdio.h and includes the complete file in the current program. stdio.h is a header file which contains the declaration of variables, macros and functions of C standard library.
2. main() function
This is the function which acts as starting point for C program. Its return type is int, which is followed as per ISO C89/99 standard. The system considers a program to have run successfully if at the end, it returns 0. So, in my opinion, this might have been the reason to choose int as the return type of main.
3. Logic
Further, more functions and logic can be included inside main() to complete a desired task. In the above program, we are only printing one line and thats "Hello World!".
4. Return value
A function's return value can be used to return a value to be used further or to get status etc. Here, 0 is being returned to the system to indicate that the program ran successfully.
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
To understand more, I would recommend to go through following:1. Preprocessor macros
# directive is for C preprocessor. #include simply looks for file stdio.h and includes the complete file in the current program. stdio.h is a header file which contains the declaration of variables, macros and functions of C standard library.
2. main() function
This is the function which acts as starting point for C program. Its return type is int, which is followed as per ISO C89/99 standard. The system considers a program to have run successfully if at the end, it returns 0. So, in my opinion, this might have been the reason to choose int as the return type of main.
3. Logic
Further, more functions and logic can be included inside main() to complete a desired task. In the above program, we are only printing one line and thats "Hello World!".
4. Return value
A function's return value can be used to return a value to be used further or to get status etc. Here, 0 is being returned to the system to indicate that the program ran successfully.
Comments
Post a Comment