In C, any function that is declared with void, for example void main()
can not return a value. However, functions that are declared with int, float
or char
MUST return a value.
#include"stdio.h"
int main()
{
printf("Hacker World");
printf("Hacker World Again");
printf("Programmers World");
return 0; // also use getch();
}
/* dev c++ softwere me void main() support nhi krta hai aap turbo c++ me void main() bhi use kr skte hai
#include<conio.h> aap use nhi krte hai aur getch(); use krenge to error aayega */
return 0
and getch()
are two different things in C programming:
return 0
is a statement used to indicate that a function (usually themain
function) has completed successfully and to return a value to the operating system. The value0
is commonly used to indicate success, but other values can also be used to indicate different types of errors or status codes.
int main() {
// code to be executed
return 0;
}
2. getch()
is a function that reads a single character from the keyboard without waiting for the user to press the Enter key. This function is not a part of the standard C library, but is provided by the conio.h header file which is non standard. It is mostly used in the Turbo C compiler.
#include <conio.h>
int main() {
char c = getch();
// code to be executed
return 0;
}
In other words return 0
is used at the end of the main function to indicate successful termination of the program and getch()
is used to read a single character from the keyboard without displaying it on the screen.
Thanks