开发者

Casting to long long (GCC)

开发者 https://www.devze.com 2023-03-01 05:46 出处:网络
long long x; double n; x=long long(n); This doesn\'t work. What is the corre开发者_开发技巧ct way?The obvious:
long long x; double n;
x=long long(n);

This doesn't work. What is the corre开发者_开发技巧ct way?


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;


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消