Datatype size is found by using the sizeof operator in c++
#include #include int main() { clrscr(); int n=10; int si=sizeof(n); char c='a'; int sc=sizeof(c); cout<<"Size of integer="< Source Code #include using namespace std; int main() { int n=10; int si=sizeof(n); char c='a'; int sc=sizeof(c); cout<<"Size of integer="< #include using namespace std; int main() { int n=10; int si=sizeof(n); char c='a'; int sc=sizeof(c); cout<<"Size of integer="< Test it !Test CPP Code !XThe code has been copied automatically for you in the clipboard. After that open any of the service and press cntrl-v to paste in the given code area. Needs a bit of tweaking as per the link. repl.it CPP cpp.sh CPP Ideone CPP Browxy CPP Show Run Output Size of integer=4 Size of character=1 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 CSKC| Created: 16-Dec-2017 | Updated: 31-Aug-2018| Post Views: 500
Size of integer=4 Size of character=1
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.
Suggested Filename(s): sizeofop.cpp, operator-sizeof.cpp
CSKC| Created: 16-Dec-2017 | Updated: 31-Aug-2018|
Operators