Skip to content

Instantly share code, notes, and snippets.

@TheSithPadawan
Created June 27, 2021 18:34
Show Gist options
  • Save TheSithPadawan/4f6430dbf1c527f23f0f15af7f51c4a2 to your computer and use it in GitHub Desktop.
Save TheSithPadawan/4f6430dbf1c527f23f0f15af7f51c4a2 to your computer and use it in GitHub Desktop.
// long and long int are identical
// int is optional
// long is a signed type size of long in c++: at least 32 bits
long x;
long int x;
// long long is a signed type of at least 64 bits
long long int x;
long long;
// problem with following code when c is really large
int i = 0;
int j = sqrt(c);
// runtime error
long res = i*i + j*j; // signed integer overflow because i*i + j*j is still treated as int type
// no runtime error by performing type cast
long res = (long) i*i + j*j;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment