545 views
0 votes
0 votes

1 int main() {
    int b;
    b = f(20,30);
    printf("%d",b);

    return 0;
}
int f(int a,int b){
    int z;
   z= a + b;
   return z;

}

this program compile fine and o/p is 50

2 int main() {
    int b;
    b = f(20,'a');
    printf("%d",b);

    return 0;
}
int f(int a,char b){
    int z;
   z= a + b;
   return z;

}

this give compilation error. I don't know why??Please explain

1 Answer

Best answer
1 votes
1 votes
You are writing the function f()  after main without declaring its prototype. Before main write int f(int,char); or write the entire function f() before main(), in that case no prototype declaration is needed.
selected by

Related questions

2 votes
2 votes
0 answers
3
robertSingh asked Sep 28, 2016
264 views
#include <stdio.h void fun(int* p) { *p = 10; } void fun1(int *p) { int a = 10; p = &a; } int main() { int x = 30; int *p = &x; fun1(p); printf("%d\n",*p); // output = 30...