#include<stdio.h>
#include<conio.h>
int main(){
printf("hello world");
}
What actually does int
do to the main
function? Is it similar to the data type int
? What does conio.h
do?
#include<stdio.h>
#include<conio.h>
int main(){
printf("hello world");
}
What actually does int
do to the main
function? Is it similar to the data type int
? What does conio.h
do?
What actually does int do to the main function?
It's the program's return code to the OS, return 0;
meaning successful execution. The OS may or may not care about it. For details, see What should main() return in C and C++?
please help me understand what does conio.h do ?
It includes a non-standard, long-since obsolete I/O library, most famously used for MS DOS programming with the ancient Borland Turbo compilers. Some compilers still supported it up to year 2000 somewhere. This lib is mostly obsolete for multiple reasons, one of them being that modern programs typically don't use console I/O but window-based GUI.
In the rare event that you must actually use console I/O, then in Windows you would typically do that through the Windows console API. In Linux there's the library nCurses.
The return value of the function is 0 because the control reaches the closed brace without the return statement.
From the C Standard (5.1.2.2.3 Program termination)
1 If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument;11) reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environment is unspecified.
If you will write
return printf("hello world");
then the returned value will be equal to the length of the string literal "hello world"
.
From the C Standard (7.21.6.3 The printf function)
3 The printf function returns the number of characters transmitted, or a negative value if an output or encoding error occurred.
As for the header <conio.h>
then it is not a standard C header and moreover in the presented program it is redundant because neither declaration from the header is used in the program.