Sizeof | SoloLearn: Learn to code for FREE!

+1

Sizeof

Sizeof('3') = 4 How ?

9/24/2019 10:18:14 AM

Shubham Kumar

11 Answers

New Answer

+6

✳AsterisK✳ Char constant are implicitly converted to int (their base type is int) if no explicit type is specified. So you will get sizeof(int) which is 4

+5

✳AsterisK✳ that mean sizeof operator do type-casting if data type is not defined?

+5

Any non-specified numeric value is an int, if it has a decimal point is a double. Then when you put this value in a variable C does a non-warning implicit cast. And that's why any library function has his one-character arguments like int, it doesn't waste computing time doing casts and with memory align.

+3

the ascii characters are integer values, which range from 1-128 this values are integers disguised a char, which in other words means its an integer value, ascii value of 3 is 51 its just like doing sizeof(51) which is an int

+3

'3' is converted to the ASCII value and being a 64-bit Machine int is 4 bytes in your system

+2

Because int is 4 bytes.

+2

If you want to see the size of the primitive data types take a look at an example I created some time ago to answer a similar question... https://code.sololearn.com/cBss8k5523i1/#cpp

+1

Drissa Sidibe imagine a white paper tape, on it you can write whatever you want, but to understand something you cannot overlap information. This tape has a finite size so if you write many things on it you can run out of space to put others. That is dynamic memory, an area of memory that is left to the programmer to put in it what he wants. What is in memory will remain between function calls and between blocks of code. Is the responsibility of the programmer to erase the unnecessary or, in languages that has garbage collector, of this functionality.

+1

Ok! Thanks you very for yor help fuster sancho !

0

i don't know how it works Internally, am trying to look it up but can't find something genuine maybe ~ swim ~ can help us out

0

Hi! Can someone help me to understand "dynamic memory" concept? Thanks!