Typecasting from int to long int

Siraj Alam picture Siraj Alam · Jun 24, 2016 · Viewed 11.5k times · Source

Recently I searched the difference between int, long int, long, ... and so on. And I got the answer from here. And I found that long and long int are identical. So the statements c = a *long(b);

and

c = a * long int (b)

should be same in the program

int main()
{
    int a = 10, b = 20;
    long int c;
    
    c = a *long(b);
    cout << c;
    
    return 0;   
}

But the second statement is showing an error

[Error] expected primary-expression before 'long'

So I just want to know, if long and long int are identical, so why there is error in the above two statements ?

Answer

Lightness Races in Orbit picture Lightness Races in Orbit · Jun 24, 2016

Just because they are the same type doesn't mean you can literally exchange the characters in your source code.

The syntax is confused by a T() cast when T has a space in it.

Write c = a * (long int)b instead.