Function should return a value in c?

Discussion in 'JavaScript' started by jantseo, Sep 22, 2011.

  1. #1
    Hi

    I have a general query. I just started learning C. But have a problem. I wrote a simple program:-

    main()

    {
    int a,b,c;
    a=10;
    b=20;
    c=a+b;

    printf("%d",c);

    }

    But enable to give output. Always a massage come: Function should return a value

    Why?
     
    jantseo, Sep 22, 2011 IP
  2. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #2
    replace main with void main() ... yaa a function should return a value.. and when it doesn't, its return type is void
     
    Rising_Star, Sep 22, 2011 IP
  3. amherstsowell

    amherstsowell Peon

    Messages:
    261
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3

    #include<stdio.h> // standard input output header file
    #include<conio.h>
    main()
    {
    int a,b,c;
    clrscr();
    a=10;
    b=20;
    c=a+b;
    printf("%d",c);
    getch();
    }


    Try this, include files it will run, but you too not doing mistake dude.
    But if you again face this problem then use void because if a function not returning a value then always use void function_name()
     
    amherstsowell, Sep 27, 2011 IP
  4. Rashmi Kamani

    Rashmi Kamani Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi,
    You should write void main() instead of main() when you are not returning any value. Your error would be solved by this.
     
    Rashmi Kamani, Sep 29, 2011 IP