C/function should return a value
Expert: Prince M. Premnath - 10/6/2011
Questioni m beginner...
I think it is very easy q. so plz tell me whr i m wrong?
When i compile this program it warns me that 'function should return a value'
#include<stdio.h>
Main()
{
Int a,b,c;
Printf(''enter the value of a='');
Scanf(''%d'',&a);
Printf(''enter the value of b='');
Scanf(''%d'',&b);
C=a+b;
Printf(''the sum of these two numbers are= %d'',&c);
}
i think the problem is that it is a c program and i run it in turbo c++
so how can i get correct o/p
AnswerHi dear Sonu,
Since the default return value of all the functions is int .. even for main() .. so the compiler will expect you to return a int value from main()..
to avoid this .. use as void main() ..
to get the output there are two options . once after completing the execution press ALT+F5 you can see the output ..
else add getch() .. function just above the closing '}' of your main() .. you supposed to include conio.h header file in order to use getch() ..
Hope this would help ..
Thanks and Regards
Prince M. Premnath