hello friends, i am a newbie in C programming its only my 10th day. i have just reached functions. if i write any user defined function the compiler give the following error. function 'sumprod' must have a prototype.. until now ie with loops and repetition control insts i had no errors.but now i am lost.. could u please guide me as to what i should do. thanks.
Your information is scanty, so I'll hazard a guess, which is a dangerous thing to do. When your compiler sees a call to a function, it has to generate machine code to call that function and it has to place the arguments in a place (which has been agreed upon before) where the function may find them. Obviously, it can't do that without knowing the number and form of the arguments. This means that the function's definition, or a description of it, must occur before the compiler encounters the call. The compiler can be appeased by writing the function before you write the part that calls it, or it can be appeased if you provide a pattern (prototype) before you call it. If you fail to meet any of these requirements in C, the compiler will assume that the function takes an int argument and returns an int. This presumption can lead to problems if the presumption is not true. C++ will not presume anything; it will merely run off into the weeds and puke on its shoes. You are the architect and designer; C/C++ is just the hourly paid slave. Do your job.
well this is the source code Code: #include<stdio.h> #include<conio.h> void main() { int a=10,b=20,c=30,s; clrscr(); s=sumprod(a,b,c); printf("\n%d",s); getch(); } sumprod(int x,int y,int z) { int ss; ss=x+y+z; printf("\n%d",ss); return(ss); }
I won't read that until you become a polite member of this society. That means reading the "Before you post a query" thread and learning to use code tags.
[COMMENT]I have added the code blocks[/COMMENT] There are 2 ways your problem can be solved. 1. Define sumprod(int x,int y,int z) above the main. 2. Have the function declaration (prototype) above the main and then have the function definition where you are having it right now.
thans shabbir,that really helped.now i can proceed in my quest of learning c. i got the 1st senario,but could not get the second one. could you please tell me what the second one means.i am really new to programing. thanks ps.how do i add code tags.
Simple. You put [/code] below the code and Code: above. You may wonder why I detailed those ***-backwards, but it was so part of my response wouldn't be rendered as code.