Pergunta

long long x; double n;
x=long long(n);

This doesn't work. What is the correct way?

Foi útil?

Solução

In any plain C / C++ compiler, in order to cast you have to use parentheses "(mytype)myvar", maybe you where confused because you required 2 separate words...

Outras dicas

The obvious:

x = (long long) n;

C does not have constructors, this looks like a C++ constructor call.

In C, the syntax of a cast is a type name in parenthesis. It works as a prefix operator, changing the type of the expression to the right:

long long x = (long long) 3.14;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top