The sizeof Operator

来源:互联网 发布:广联达软件配置要求 编辑:程序博客网 时间:2024/05/16 15:16
// TestSizeof.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <climits>int _tmain(int argc, _TCHAR* argv[]){using namespace std;int n_int = INT_MAX;int n_short = SHRT_MAX;  //symbol defined in climits files;int n_long = LONG_MAX;int n_llong = LLONG_MAX;//sizeof operator yields size of type or of vatiable;cout << "int is" << sizeof(int) << "bytes." << endl;cout << "short is" << sizeof n_short << "bytes." << endl;cout << "long is" << sizeof n_long <<  "bytes." << endl;cout << "long long is" << sizeof n_llong <<  "bytes." << endl;cout << endl;cout << "Max value is" << endl;cout << "int:" << n_int << endl;cout << "short:" << n_short << endl;cout << "long:" << n_long << endl;cout << "long long" << n_llong << endl << endl;cout << "Minimum int value" << INT_MIN << endl;return 0;}

The running result:


You can apply the sizeof operator to a type name or to a variable name. When you use the sizeof operator with a type name ,suach as int, you enclose the name int parentheses. But when you use the operator with name of the variable,such as n_short,parentheses are optentional.














0 0