what is the difference between the two:
and can someone explain what does a destructive and non-destructive function mean?Code:int main (void) { return 0; } and int main () { return 0; }
thx very much
what is the difference between the two:
and can someone explain what does a destructive and non-destructive function mean?Code:int main (void) { return 0; } and int main () { return 0; }
thx very much
One specifies that there are no parameters, and the other specifies an unknown number of parameters.
Destructive is bad. Non-destructive is not destructive.
Quzah.
Hope is the first step on the road to disappointment.
I've never heard of the term but a quick search turned up this:
Failure of Implicit Conventions: Determining Function Destructiveness
" destructive functions cause some change outside of the lexical scope of their function, whereas non-destructive functions do not cause changes outside of their lexical scope."
Last edited by nonoob; 03-08-2010 at 08:44 PM.
void specifies no arguments.
In the above code I didn't use void in the main function.Code:#include<stdio.h> #include<stdlib.h> static int i=1; int main() { printf("function"); if(i++==5) exit(0); main(2); }
I called the main function with the argument 2.So the message "function" will get printed for five times.
If I changed the code like the following,
I have used the void as a argument type.So main function wont accept any argument.So it will throw an error.Code:#include<stdio.h> #include<stdlib.h> static int i=1; int main(void) { printf("hai"); if(i++==5) exit(0); main(2); }
Just started to learn C programming. Does anyone know why I get a error with this code. The program runs fine in the console but in Xcode it gives me an error saying "Return type defaults to "int"" next to the main (int argc, const char* argv[]) { part of the code. Thank you for your help!
#include <stdio.h>
main (int argc, const char* argv[]) {
int i;
i = 20;
printf("Number %d is Peter's favorite number\n", i);
return 0;
}
You didn't specify a return type for main.
Quzah.
Hope is the first step on the road to disappointment.