Use of 003--sizeof

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.