There are a bunch of ways to make the main part of a program like int main() and int main(void) and void main ect. What are the types and how are they used?
There are a bunch of ways to make the main part of a program like int main() and int main(void) and void main ect. What are the types and how are they used?
--Seph
int main() // same as int main(void)
- or -
int main(int argc, char ** argv)
Since all C functions return an int whenever you don't specify, you could also use:
main()
- or -
main(int, char**)
Remember:
void main()
- and -
void main(int, char**)
...are not correct, since 'main' *always* returns an int.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
When you start a program, you have todo includes like stdin.h, conio.h, string.h, and ect. How do you know when to use them.
--Seph
>> How do you know when to use them?
Whenever the compiler complains that you're using an undeclared function.
When you're a newbie, it's often easiest to create a special header of your own that simply includes most of the standard headers:
Code:// inc.h #ifndef INC_H #define INC_H #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #endif // INC_H
Then in your program you'd simply do:
Code:#include <inc.h> int main() { printf("Hello world!"); }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
wouldnt that just waste memory though. Like if i never used anything from math.h, it would be included into the program anyway and that would make the program bigger.
--Seph
Go back to your last question then. You have to know what functions are located where. So open the headers and find out what functions are there. Then you'll know.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
I would've thought a savvy compiler would only include the bits your source was actually using, so if you include math.h and don't use anything from it, the compiler will use it to search for stuff (So compilation takes a few milliseconds longer) but the size of the compiled file would be no different than if you omitted it.Originally posted by Seph_31
wouldnt that just waste memory though. Like if i never used anything from math.h, it would be included into the program anyway and that would make the program bigger.
shouldn't it be #include "inc.h"Originally posted by Sebastiani
>> How do you know when to use them?
Code:// inc.h #ifndef INC_H #define INC_H #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #endif // INC_HCode:#include <inc.h> int main() { printf("Hello world!"); }
is there a difference?
i'm not sure, can somebody clarify?
is always between < and >Code:#include
No idea why, I'm novice also...hope to learn C by just simply reading the topics.
When using #include anything between < and > is taken to be in the default include directory of your compiler. If you use quation marks (") then it will look for the file in the same directory as the source file. When you make your own header file you include by usingThis is because it is in the same directory and not the default directory with all the standard header files.Code:#include "Inc.h"
- Sean
If cities were built like software is built, the first woodpecker to come along would level civilization.
Black Frog Studios
Not true, it says the difference in the faq posted above.Originally posted by Sebastiani
int main() // same as int main(void)
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
Close. If you use quotation marks, it looks in the same directory, THEN the default include directory. But it doesn't usually matter, when quotes are used, its usually in the same dir .Originally posted by sean345
When using #include anything between < and > is taken to be in the default include directory of your compiler. If you use quation marks (") then it will look for the file in the same directory as the source file.
Do not make direct eye contact with me.
Going back-thread for a moment:
Just to note that this is no longer true in C.Originally posted by Sebastiani
Since all C functions return an int whenever you don't specify, you could also use:
main()
- or -
main(int, char**)
Try it and see. Post your results here, with the compiler used.Originally posted by SMurf
I would've thought a savvy compiler would only include the bits your source was actually using, so if you include math.h and don't use anything from it, the compiler will use it to search for stuff (So compilation takes a few milliseconds longer) but the size of the compiled file would be no different than if you omitted it.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers