Code:#include<stdio.h> #include<conio.h> void get() { printf("Hello\n"); } main() { clrscr(); get(10,20); getch(); return 0; } When a call is made to the get fn with (any number of) auguments it works. Why is that happening? Help me out please.
Code:#include<stdio.h> #include<conio.h> void get() { printf("Hello\n"); } main() { clrscr(); get(10,20); getch(); return 0; } When a call is made to the get fn with (any number of) auguments it works. Why is that happening? Help me out please.
Because you defined get with an undefined number of arguments. Try void get(void).
The same gives errors in c++.Is that the default type of augument in c is void and c++ is not void?
I think so (I could be wrong)... specifying no arguments when you create your function "get" as you have done for C means that the function accepts an undefined number of arguments (as already mentioned by Brian). In C++ however, specifying no arguments means that the function does not accept any arguments at all and you will get errors if you try to call the function with any arguments.Originally Posted by lydiapeter
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
C has declarations and prototypes. They are seperate things. C++ has declarations and prototypes too, however they are the same thing.
In C: T fn() is a declaration. It provides no information on the parameters and that basicaly means anything goes. T fn(void) in C is a declaration, and a prototype. All prototypes are declarations, not all declarations are prototypes. This is a prototype because it provides type information for the parameters (in this case no parameters).
With void get(), you are neglecting to provide information about the arguments, so the compiler accepts any number. void get(void) tells the compiler that this function takes no arguments.
On the same line, you should declare main like this:
Code:int main(void) { /* ... */ return 0; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.