尽管我们已经谈到了sizeof运算符,我们将再简要的完整性。sizeof操作符返回字节大小,,的类型或变量。
你可以编译并运行下面的程序来找出你有多大的数据类型:
|
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;} |
bool: 1 bytes
char: 1 bytes
wchar_t: 2 bytes
short: 2 bytes
int: 4 bytes
long: 4 bytes
float: 4 bytes
double: 8 bytes
long double: 8 bytes算术运算符(如?:)也被称为有条件的经营者,这是C++的只有三元运算符(需要3个操作数)。的?:操作者提供了一个速记的方法做一个特定类型的if/else语句。
如果别的以下表格报表:
|
1
2
3
4
|
if
(x > y) z
= x;else z
= y; |
1830

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



