+ 2

what is the logic???

when I write code #include <stdio.h> int main() { printf("int: %d \n", sizeof(int)); printf("float: %d \n", sizeof(float)); printf("double: %d \n", sizeof(double)); printf("char: %d \n", sizeof(char)); return 0; } output as under: int: 4 float: 4 double: 8 char: 1 My question is from where the values shown in the output fetched from?

28th Sep 2018, 7:50 AM
deepak sharma
deepak sharma - avatar
4 Respostas
+ 15
It outputs how much memory variable of each data type takes in bytes.
28th Sep 2018, 7:53 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 4
It is the number of bytes. int and float use 4 bytes of memory, double uses 8 bytes, and char only need 1 byte of memory. 1 byte = 8 bit (0 or 1)
28th Sep 2018, 7:52 AM
Matthias
Matthias - avatar
+ 3
Read here https://en.m.wikipedia.org/wiki/Sizeof in particular the "implementation" section
28th Sep 2018, 8:53 AM
KrOW
KrOW - avatar
+ 2
This fetched from the pre-processor macro DATATYPE_BIT, defined in the standard include file limits.h file. And in the above program the size of function returns a long int value but %d is for integer there is a warning in this program.
8th Aug 2020, 6:07 AM
Chethan GC
Chethan GC - avatar