+ 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?
4 Respostas
+ 15
It outputs how much memory variable of each data type takes in bytes.
+ 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)
+ 3
Read here https://en.m.wikipedia.org/wiki/Sizeof in particular the "implementation" section
+ 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.