简体   繁体   English

形式(类型)(值)的表达式的含义是什么?

[英]What is the meaning of an expression with the form (type) (value)?

I have this line: 我有这条线:

lsb = (char) (intNumber & 0xff);

and I'm confused as to why is it written like 我对为什么写成这样感到困惑

name = (type) (value)

What does it exactly mean, or what is the purpose of defining a variable like that? 它到底是什么意思,或者定义这样的变量的目的是什么?

lsb = (char) (intNumber & 0xff); intNumber has been and -ed with 0x11111111 and subsequently typecast to 8-bit character, hence it finds the least significant byte of a variable. intNumber已经 -ed与0x11111111并随后强制转换为8位的字符,因此,它找到一个变量的至少显著字节。

That is the syntax to typecast a variable eg: 这是类型转换变量的语法,例如:

float x = 5.55;
int y = (int)x; // in this case, the casting would have happened implicitly
// or 
printf("%d",(int)x);
// this will display 5

Here by specifying constant/variable will be converted to whatever type you mention inside your first pair of brackets. 通过指定常量/变量,此处将转换为您在第一对方括号内提到的任何类型。

该行表示您要强制转换右侧表达式所给出的结果,以使其变为char,以便适合左侧的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM