When I use main(),the compiler warns that the function should return a value.To what it should return? Why?
What is the difference between the usage of main() and void main() in C-PROGRAMMING?
Normal convention is that main() is defined as int main() and that it should return a value that signals whether the program completed successfully or not. A return value of 0 (zero) is normally the success state and anything else is an error value.
If your program doesn't need to return a value to the command line, then define main as void main().
Reply:main() is the part where we can have the main content of the program ,it returns a value. Bt in void ()it does'nt returns a value.
Reply:Without specifying anything as return value, int is assumed, so "main()" is equivalent to "int main(void)".
As yet stated, by convention main must return int and takes some arguments, so the common way is:
int main (int argc, char **argv)
PS: the int returned by main can be used by the operating system.
Reply:both are similar
don't u meaningo void main()
for example-in school a whole staff can work
1st is principal
2nd is teachers
3rd is students
principal is void main
teacher is printf and scanf
and getch() is student who gave u out put
Reply:dear friend
main() is a function that always need to return some value in the function. otherwise it will show you some warning message while compiling. but void main() do not need any return value.
i.e
main()
{
int x=5,y=2,z;
z=x*y;
return(z);
}
and
void main()
{
int x=5,y=2,z;
z=x*y;
}
for more details on any problem related to any topic pls contact:
http://www.jjnavsofs.we.bs
http://jjnavsofs.110mb.com
http://jjnavsofs.x10hosting.com
jaisingh1006@gmail.com
Reply:both are same because in main() you may return 0 or may not and compiler give warning if you don't return any value BUT NOT ERROR,and in void main() you must not return any value.
Reply:whenever you write void main (), it means that the main program does not return anything but if we write main() then the compiler takes it to be int by default and in that case you have to return something in the end of the main() function. You can return 0 by typing :
return 0;
This shall satisfy you
Reply:u get this error because u canot return any value to the main() function it shouls always have a return data type even though u don't retun any thing.void means it is empty u r not retuning any thing but if u do int main() return type willl be int
this all because at the end u have return 0 or getch() function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment