You are here:

C/function should return a value

Advertisement


Question
i 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

Answer
Hi 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  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.