I have the following c program, and some of the times I run it, the output differs, based on the compiler and the platform. I understand that double to int conversion could cause problems.  Here is the code:  //Compiler version gcc 6.3.0 #include &lt;stdio.h&gt; #include &lt;math.h&gt;  int main(void){     double d = 2;     printf("%.20lf\n", pow(10, d));     printf("%d\n", (int)pow(10, d));     printf("%d\n", (int)pow(10, 2)); }   100 is the expected value, but the statement      printf("%d\n", (int)pow(10, d));   has 99 as output when I use both gcc 6.3.0 and Windows 10 x64, but not in other cases.  Here are some results:  //gcc 6.3.0 (Sublime Text 3) in Windows 10 x64 100.00000000000000000000 99 -&gt;this is the problem 100  //gcc 6.3.0 in Android (using Dcoder app) 100.00000000000000000000 100 100  //MSVC(VS 2017 x86) in Windows 10 x64 100.00000000000000000000 100 100   I also tested some online gcc(6.3.0) compilers but all the outputs were 100.  Thanks for the help.
27
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
80880
My code:  a = '2.3'   I wanted to display a as a floating point value.  Since a is a string, I tried:  float(a)   The result I got was :  2.2999999999999998   I want a solution for this problem. Please, kindly help me.  I was following .
9588
I was writing a program in C++ to find all solutions of ab = c, where a, b and c together use all the digits 0-9 exactly once. The program looped over values of a and b, and it ran a digit-counting routine each time on a, b and ab to check if the digits condition was satisfied.  However, spurious solutions can be generated when ab overflows the integer limit. I ended up checking for this using code like:  unsigned long b, c, c_test; ... c_test=c*b;         // Possible overflow if (c_test/b != c) {/* There has been an overflow*/} else c=c_test;      // No overflow   Is there a better way of testing for overflow? I know that some chips have an internal flag that is set when overflow occurs, but I've never seen it accessed through C or C++.    Beware that signed int overflow is undefined behaviour in C and C++, and thus you have to detect it without actually causing it. For signed int overflow before addition, see .
4461
This prints 83  System.out.println(0123)   However this prints 123  System.out.println(123)   Why does it work that way?
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?
60259
What is the difference between decimal, float and double in .NET?  When would someone use one of these?
106074
Why doesn't Java include support for unsigned integers?    It seems to me to be an odd omission, given that they allow one to write code that is less likely to produce overflows on unexpectedly large input.    Furthermore, using unsigned integers can be a form of self-documentation, since they indicate that the value which the unsigned int was intended to hold is never supposed to be negative.    Lastly, in some cases, unsigned integers can be more efficient for certain operations, such as division.    What's the downside to including these?
69127
I'm looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler.  But are there any standards for C++?  I'm using Visual Studio 2008 on a 32-bit architecture. Here is what I get:  char  : 1 byte short : 2 bytes int   : 4 bytes long  : 4 bytes float : 4 bytes double: 8 bytes   I tried to find, without much success, reliable information stating the sizes of char, short, int, long, double, float (and other types I didn't think of) under different architectures and compilers.
41565
The printf function takes an argument type, such as %d or %i for a signed int. However, I don't see anything for a long value.
99240
I write financial applications where I constantly battle the decision to use a double vs using a decimal.  All of my math works on numbers with no more than 5 decimal places and are not larger than ~100,000. I have a feeling that all of these can be represented as doubles anyways without rounding error, but have never been sure.  I would go ahead and make the switch from decimals to doubles for the obvious speed advantage, except that at the end of the day, I still use the ToString method to transmit prices to exchanges, and need to make sure it always outputs the number I expect. (89.99 instead of 89.99000000001)  Questions:   Is the speed advantage really as large as naive tests suggest? (~100 times) Is there a way to guarantee the output from ToString to be what I want? Is this assured by the fact that my number is always representable?   UPDATE: I have to process ~ 10 billion price updates before my app can run, and I have implemented with decimal right now for the obvious protective reasons, but it takes ~3 hours just to turn on, doubles would dramatically reduce my turn on time. Is there a safe way to do it with doubles?
17725
What is the most efficient way given to raise an integer to the power of another integer in C?  // 2^3 pow(2,3) == 8  // 5^5 pow(5,5) == 3125
6890
What is the difference between g++ and gcc?  Which one of them should be used for general c++ development?
43933
#include &lt;stdio.h&gt; int main() {     unsigned long long int num = 285212672; //FYI: fits in 29 bits     int normalInt = 5;     printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);     return 0; }   Output:  My number is 8 bytes wide and its value is 285212672l. A normal number is 0.   I assume this unexpected result is from printing the unsigned long long int. How do you printf() an unsigned long long int?
93954
I had an article, but I lost it.  It showed and described a couple of C/C++ tricks that people should be careful. One of them interested me but now that I am trying to replicate it I'm not being able to put it to compile.  The concept was that it is possible to change by accident the value of a const in C/C++  It was something like this:  const int a = 3;          // I promise I won't change a const int *ptr_to_a = &amp;a; // I still promise I won't change a int *ptr; ptr = ptr_to_a;  (*ptr) = 5;               // I'm a liar; a is now 5   I wanted to show this to a friend but now I'm missing a step.  Does anyone know what's missing for it to start compiling and working?  ATM I'm getting invalid conversion from 'const int*' to 'int*' but when I read the article I tried and it worked great.
123209
I'm trying to write a basic program in C using gedit or sublime text (which I prefer), but no matter what I do when I try to compile or run, or even while writing, I have no option to use 'stdio.h' or any similar package. Even when I start typing #include &lt;st the only word completion sublime suggests is 'struct'.  I've read dozens of threads, but all managed to fix this by installing gcc, which I've tried to reinstall multiple times, with no luck.  This is the output from gcc -v:  Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.2.0-8ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3) `   This is the code:   #include &lt;stdio.h&gt;  int main(void) { printf("hello, world\n"); }   When I compile using gcc, I get nothing, no error at least. but when I try to run using just ./hello.c this is what I get.
43864
The following code snippet (correctly) gives a warning in C and an error in C++ (using gcc &amp; g++ respectively, tested with versions 3.4.5 and 4.2.1; MSVC does not seem to care):  char **a; const char** b = a;   I can understand and accept this. The C++ solution to this problem is to change b to be a const char * const *, which disallows reassignment of the pointers and prevents you from circumventing const-correctness ().  char **a; const char* const* b = a;   However, in pure C, the corrected version (using const char * const *) still gives a warning, and I don't understand why. Is there a way to get around this without using a cast?  To clarify: 1) Why does this generate a warning in C?  It should be entirely const-safe, and the C++ compiler seems to recognize it as such. 2) What is the correct way to go about accepting this char** as a parameter while saying (and having the compiler enforce) that I will not be modifying the characters it points to? For example, if I wanted to write a function:  void f(const char* const* in) {   // Only reads the data from in, does not write to it }   And I wanted to invoke it on a char**, what would be the correct type for the parameter?
108041
I'm a rookie programmer and trying to compile a C code in Ubuntu. I already installed GCC. How do I proceed from here?