Why you are forcing on return type to be int.

Why you are forcing on return type to be int.?
One can do with void as well and that is also right I guess.
I ran code on gcc 4.7.1 showed right. but when I submitted it gave error
"prog.c: In function ‘main’: prog.c:3: warning: return type of ‘main’ is not ‘int’ /home/BS2Zys/cc8azcJC.o: In function main': prog.c:(.text+0x46): undefined reference to getch’ collect2: ld returned 1 exit status ".

saw ur code the simple problem is that u giving ur solution in turbo c compiler format but codechef uses gcc compiler.
gcc compiler uses int return type u cannot use void main here
For gcc do not use conio.h in C this is not part of the C standard library, Do not use iostream.h; this is a deprecated header file and again is not a standard library.
secondly u should check the proper functioning of gcc compiler the turbo c compiler is not standard compiler
eg;
#include<stdio.h>
int main()
{

return 0;
}
would work in gcc as well as turbo c
but
#include<stdio.h>
#include<conio.h>
void main()
{

getch();
}
would work only on turbo c
make habit of using gcc compiler now.:slight_smile:

2 Likes

nice answer

2 Likes

My friend,Some compilers force you not to use void as a return type because the developers set some standerds for the users and they want the users to get the output as return value “0” or “1”.
moreover the kernel of linux has some mechanism that collects either “0” or “1” value from the “main” and hence we cant use “void” upthere and we use “int main()” with two optional arguments “argc”,“argv”. :slight_smile:

I think it’s not restricted to 0 and 1 only, but return type 0 means ok and whatever different is error.