这是常见的把括号内的表达条件部分,以使它更容易阅读,并确定优先是正确的。
记住?:算子具有非常低的优先级。如果做的比其他任何使用导致一个赋值语句(具有更低的优先级),对吗?:声明需要用括号。
例如,要打印的值x和y的屏幕更大,我们可
以这样做:
|
1
2
3
4
|
if
(x > y) cout
<< x;else cout
<< y; |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include
<iostream>int
main(){ using
namespace
std; cout
<< "bool:\t\t"
<< sizeof(bool)
<< "
bytes"
<< endl; cout
<< "char:\t\t"
<< sizeof(char)
<< "
bytes"
<< endl; cout
<< "wchar_t:\t"
<< sizeof(wchar_t)
<< "
bytes"
<< endl; cout
<< "short:\t\t"
<< sizeof(short)
<< "
bytes"
<< endl; cout
<< "int:\t\t"
<< sizeof(int)
<< "
bytes"
<< endl; cout
<< "long:\t\t"
<< sizeof(long)
<< "
bytes"
<< endl; cout
<< "float:\t\t"
<< sizeof(float)
<< "
bytes"
<< endl; cout
<< "double:\t\t"
<< sizeof(double)
<< "
bytes"
<< endl; cout
<< "long
double:\t"
<< sizeof(long
double)
<< "
bytes"
<< endl; return
0; |
尽管我们已经谈到了sizeof运算符,我们将再简要的完整性。sizeof操作符返回字节大小,,的类型或变量。
你可以编译并运行下面的程序来找出你有多大的数据类型:
3663

被折叠的 条评论
为什么被折叠?



