function calsum should have a prototype??

This is a discussion on function calsum should have a prototype?? within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> void main() { int a,b,c,sum; printf("\nEnter three num "); scanf("%d%d%d",&a,&b,&c); sum=calsum(a,b,c); printf("\nsum=%d",sum); } calsum(x,y,z) int x,y,z; { int ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    22

    function calsum should have a prototype??

    Code:
    #include<stdio.h>
    void main()
    {
    int a,b,c,sum;
    printf("\nEnter three num ");
    scanf("%d%d%d",&a,&b,&c);
    sum=calsum(a,b,c);
    printf("\nsum=%d",sum);
    }
    calsum(x,y,z)
    int x,y,z;
    {
    int d;
    d=x+y+z;
    return(d);
    }



    error on compiling on tc++

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,056
    You can define a function before "main()".

    You can also define a function after "main()", but it must be declared before "main()" with a prototype.

    Code:
    // Method 1 - define a function before main
    
    #include <stdio.h>
    
    int sum(int a, int b)
    {
        return a + b;
    }
    
    int main(void)
    {
        int result;
    
        result = sum(2,3);
    
        return 0;
    }
    Code:
    // Method 2 - define a function after main
    
    #include <stdio.h>
    
    int sum(int a, int b);  // function declaration, or prototype (note semicolon)
    
    int main(void)
    {
        int result;
    
        result = sum(2,3);
    
        return 0;
    }
    
    int sum(int a, int b)  // function definition (note no semicolon)
    {
        return a + b;
    }
    The return type, function name, and function arguments in the function definition should match those of the function prototype.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function prototype
    By Lina_inverse in forum C Programming
    Replies: 6
    Last Post: 10-07-2012, 08:59 PM
  2. Function Prototype
    By popnfresh12321 in forum C Programming
    Replies: 1
    Last Post: 05-06-2012, 09:36 PM
  3. function prototype
    By eurikau in forum C Programming
    Replies: 1
    Last Post: 07-31-2007, 01:19 AM
  4. function prototype
    By shuo in forum C++ Programming
    Replies: 9
    Last Post: 04-19-2007, 09:25 PM
  5. Replies: 13
    Last Post: 08-24-2006, 12:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21