I have started learning C++ from Josh Lospinoso's C++ Crash Course.
I am unable to wrap my mind around 'types'.
What is the difference between long long int a=50
and int a =50LL
?
To me, they both look like long long int
I tried to run this:
#include<cstdio>
int main() {
long long int a=50;
int b=50LL;
printf("a is %lld and b is %lld",a,b);
}
and got :
a is 50 and b is 18042367336513586
So there is something wrong with either the format specifier or int b=50LL
On changing the format specifier of b to %d
. I get:
a is 50 and b is 50
So does this mean that b
is the default 'int' ? If yes, what is the role of LL
then?
On surfing about types, I came across this. So I tried running this:
#include <iostream>
#include <typeinfo>
int main(){
long long int a = 50;
int b = 50LL;
std::cout << typeid(a).name() << std::endl;
std::cout << typeid(b).name() << std::endl;
return 0;
}
which gave
x
i
So they are indeed of different types (?). But Why?