You are here:

C/c language

Advertisement


Question
what do you understand when compiling program give error that "function should return a value".

Answer
Hi Sofia

When your compiling program says 'Function should return a value' it means that you have declared a function with a return value, but when you actually define the function, you have not returned any value from it. Eg:

#include <stdio.h>

int add_num(int, int);      //This is the declaration part which specifies a return type of 'int'

void main(){
int sum;
sum=add_num(5,6);
}

int add_num(int a, int b){
int s;
s=a+b;}                  //Although this function is adding the numbers, it is not returning
                        //any value as stated in the declaration


Such a program will give the 'Function should return a value' error

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Smitha Renny

Expertise

I can answer questions related to basic understanding of C concepts, arrays, pointers and their handling well.

Experience

I've been programming in BASIC since 1987. Later moved onto Pascal for a short period and then hooked onto C since 1997.

Education/Credentials
I have completed a Post-Graduate diploma in Computer Applications. Currently doing MCA

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