I was recently coding in C++ when I realized that the int main() function works fine as a long main() and can support larger numbers (up to 2^63) so why is that not the normal way it is coded?
2571
What is the correct (most efficient) way to define the main() function in C and C++ — int main() or void main() — and why? And how about the arguments? If int main() then return 1 or return 0?  There are numerous duplicates of this question, including:       — For C++, with a very good answer indeed.     Related:
30179
In C the following horror is valid:  myFunc() {   return 42;  // return type defaults to int. }   But, what about in C++? I can't find a reference to it either way...  My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this is an error in C++.
40034
Coming from C++ to Java, the obvious unanswered question is why didn't Java include operator overloading?  Isn't Complex a, b, c; a = b + c; much simpler than Complex a, b, c; a = b.add(c);?  Is there a known reason for this, valid arguments for not allowing operator overloading? Is the reason arbitrary, or lost to time?
66958
I want to do:  int a = 255;  cout &lt;&lt; a;   and have it show FF in the output, how would I do this?
113560
I expected A::~A() to be called in this program, but it isn't:  #include &lt;iostream&gt;  struct A {   ~A() { std::cout &lt;&lt; "~A()" &lt;&lt; std::endl; } };  void f() {   A a;   throw "spam"; }  int main() { f(); }   However, if I change last line to   int main() try { f(); } catch (...) { throw; }   then A::~A() is called.  I am compiling with "Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86" from Visual Studio 2005. Command line is cl /EHa my.cpp.  Is compiler right as usual? What does standard say on this matter?
40309
What is the best way to convert a double to a long without casting?  For example:  double d = 394.000; long l = (new Double(d)).longValue(); System.out.println("double=" + d + ", long=" + l);
610
I've always wondered how to write the "A ? B : C" syntax in a C++ compatible language.  I think it works something like: (Pseudo code)  If A &gt; B    C = A Else    C = B   Will any veteran C++ programmer please help me out?
113353
I'm working with large numbers that I can't have rounded off.  Using Lua's standard math library, there seem to be no convenient way to preserve precision past some internal limit.  I also see there are several libraries that can be loaded to work with big numbers:      (might be identical to #2)  (but I can't find any source)   Further, there are  in C that could be called from Lua, if the bindings where established.  Have you had any experience with one or more of these libraries?
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
116782
Possible Duplicate:          see this code    #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))     int array[] = {23,34,12,17,204,99,16};     int main()     {         int d;         for(d=-1;d &lt;= TOTAL_ELEMENTS-2;d++)            printf("%d\n",array[d+1]);         return 0;    }    now this loop won't run. sizeof() would return an unsigned value so TOTAL_ELEMENTS has an unsigned value. now , coming to the for loop, please tell me if the unary operator '-' works on signed int 2 or an implicit conversion takes place into unsigned and then the '-' operator works.
67645
I know that a float isn't appropriate to store currency values because of rounding errors. Is there a standard way to represent money in C++?   I've looked in the boost library and found nothing about it. In java, it seems that BigInteger is the way but I couldn't find an equivalent in C++. I could write my own money class, but prefer not to do so if there is something tested.
22068
Why is Array.Length an int, and not a uint. This bothers me (just a bit) because a length value can never be negative.   This also forced me to use an int for a length-property on my own class, because when you  specify an int-value, this needs to be cast explicitly...  So the ultimate question is: is there any use for an unsigned int (uint)? Even Microsoft seems not to use them.
55243
In C#, int and Int32 are the same thing, but I've read a number of times that int is preferred over Int32 with no reason given. Is there a reason, and should I care?
44048
I'm working on a C-brain teaser:  Write the standard Hello-World program, without semi-colons.  My best answer so far is:  int main(void) {     if (printf("Hello World!\n"), exit(0), 0)     {         /* do nothing */     } }   But I don't understand why I don't get compiler error (Visual Studio):  error C4716: 'main' : must return a value   I've tried other functions with a return-type declared, but missing a return-statement, and get this compiler error.    Note that I've also tried:  int foo(void) {     if (printf("Hello World!\n"), exit(0), true)     {         /* do nothing */     } }  int main(void) {     foo(); }   And don't get a compiler error on foo.  If I remove the "exit(0)", I do get the compiler error.  Apparently the compiler has knowledge that "exit" is a special function?  This seems very odd to me.
35378
For example:  int a = 12; cout &lt;&lt; typeof(a) &lt;&lt; endl;   Expected output:  int
11288
I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main:  int main(array&lt;System::String ^&gt; ^args)   I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really means, but couldn't find one.  Obviously it means the same as the standard int main(int argc, char *argv[]), but I'd like to know when and why that ^ is really used, and why it even exists (does it do something that pointers * and references &amp; cannot represent)?
89137
What would be better practice when giving a function the original variable to work with:  unsigned long x = 4;  void func1(unsigned long&amp; val) {      val = 5;             } func1(x);   or:  void func2(unsigned long* val) {      *val = 5; } func2(&amp;x);   IOW: Is there any reason to pick one over another?