sizeof operator – CSKC
Sign In

Search

Code Learning #CPP#1750    siteicon   siteicon  

sizeof operator

Datatype size is found by using the sizeof operator in c++

Learning Objectives

  • Understanding sizeof as an operator.

Source Code

TC++ #1750

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

int n=10;Β int si=sizeof(n);
Here si will contain the size which is occupied in memory by the variable n. Since n is an integer variable, it will occupy 4 bytes in most modern operating systems. In older systems it was 2 bytes.

char c=’a’;Β int sc=sizeof(c);
Here sc will contain the size occupied by variable c, which has earlier been defined as a character type variable. A single char is always defined as 1 byte.

Notes

  • Most modern compilers also support the char16_t and char32_t declaration which are 2 byte and 4 byte respectively.
  • The declaration wchar_t is compiler dependent, which can be 1 byte, 2 byte or more.The sizeof usage for many primitive data types can also be seen from following code sheet.
    Finding Size of CPP Data Types


Suggested Filename(s): sizeofop.cpp, operator-sizeof.cpp



Share

Created: 16-Dec-2017 23:53 | Updated: 31-Aug-2018 12:29|