Line 1: declared outside main() , working fine
#include<stdio.h> #include<conio.h> struct prod { int price,usold; }; int main() { struct prod *p,a; int billamt(struct prod *); int bill; printf("enter the values \n"); scanf("%d%d",&p->price,&p->usold); bill=billamt(p); printf("bill=%d",bill); getch(); } int billamt(struct prod *i) { int b; b=(i->price*i->usold); return b; }
Case 2: declared inside main() , indicating an error
[Error] type 'main () :: prod' without the link used to declare the function 'int billamt (main () :: prod *)' with the binding [-fpermissive] *
#include<stdio.h> #include<conio.h> int main() { struct prod { int price,usold; }; struct prod *p,a; int billamt(struct prod *); int bill; printf("enter the values \n"); scanf("%d%d",&p->price,&p->usold); bill=billamt(p); printf("bill=%d",bill); getch(); } int billamt(struct prod *i) { int b; b=(i->price*i->usold); return b; }
source share