+ 3

This program is to give the sizeof data types, But why it's giving output as 4 for int.

https://code.sololearn.com/cCKMWQ7luw8x/?ref=app

9th Sep 2018, 3:35 PM
Roland Mendonca
Roland Mendonca - avatar
3 Antworten
+ 12
The sizeof returns number of bytes required for the certain type you passed to it. In this case you passed int and get 4 bytes, or 32 bit (one byte = 8 bit), however, actual size of each type depends on system and compiler. Hth, cmiiw
9th Sep 2018, 3:43 PM
Ipang
+ 4
Ipang Not of all types. There are actually types specially made to have fixed sizes, like _u16(i think its this way) and its family.
9th Sep 2018, 5:15 PM
Bebida Roja
Bebida Roja - avatar
+ 3
Because an int is actually most of the time 4 bytes :) I said "most of the time" because it's really compiler dependant so using sizeof is a good practice to ensure your program will compile on most machines :)
9th Sep 2018, 3:49 PM
darrencweid
darrencweid - avatar