sizeof is used to obtain the memory size of a type or variable. You can use sizeof for a type name or variable. When you use the sizeof operator for a type, such as int, you should enclose the name in parentheses, but use the operator for the variable name (n_short), and the parentheses are optional:
1#include <iostream>2#include <climits>3 4 intMain () {5 using namespacestd;6 intN_int=Int_max;7 Shortn_short=Shrt_max;8 Longn_long=Long_max;9 Long Longn_llong=Llong_max;Ten Onecout<<"int is"<<sizeof(int) <<"bytes."<<Endl; Acout<<" Short is"<<sizeofn_short<<"bytes."<<Endl; -cout<<"Long is"<<sizeofn_long<<"bytes."<<Endl; -cout<<"Long Long is"<<sizeofn_llong<<"bytes."<<Endl; thecout<<Endl; - -cout<<"Maximum values:"<<Endl; -cout<<"int:"<<n_int<<Endl; +cout<<"Short :"<<n_short<<Endl; -cout<<"Long:"<<n_long<<Endl; +cout<<"Long Long:"<<n_llong<<Endl; A atcout<<"Minimum int Value:"<<INT_MIN<<Endl; -cout<<"Bits per byte:"<<CHAR_BIT<<Endl; - - return 0; -}View Code
Use of 003--sizeof