Why the output of the program is "4, 4, 8, 1"??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the output of the program is "4, 4, 8, 1"???

#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; }

25th Sep 2018, 12:48 PM
Khokhar Jeelani
Khokhar Jeelani - avatar
8 Answers
+ 2
Ok thank you bro Niek Aukes
25th Sep 2018, 12:57 PM
Khokhar Jeelani
Khokhar Jeelani - avatar
+ 1
Niek Aukes plz can you answer me in detail. Thank you😊
25th Sep 2018, 12:54 PM
Khokhar Jeelani
Khokhar Jeelani - avatar
+ 1
Well, an int takes 4 bytes in the memory, double takes 8 bytes. Its measuring the size of the data. Mostly you won't use it much since current memory is at least more than a gigabyte
25th Sep 2018, 12:56 PM
CodeMStr
CodeMStr - avatar
+ 1
Niek Aukes As far as I know, int requires 2 bytes?
25th Sep 2018, 2:17 PM
Vaibhav
Vaibhav - avatar
0
Int- 4 bytes float - 4 bytes double - 8 bytes Char - 1 byte If you were asking something else, leave a reply
25th Sep 2018, 12:53 PM
CodeMStr
CodeMStr - avatar
0
Vaibhav I think you mean short ints, they require 2 bytes, but can't surpass the number 32768 since all bits are used
25th Sep 2018, 2:20 PM
CodeMStr
CodeMStr - avatar
0
But if not mentioned, sizeof(int) will give as 2
25th Sep 2018, 2:26 PM
Vaibhav
Vaibhav - avatar
0
#include <stdio.h> int main() { printf("int: %d \n", sizeof(int)); printf("short: %d \n", sizeof(short)); return 0; } Int: 4 Short: 2 Vaibhav highly doubt it
25th Sep 2018, 2:35 PM
CodeMStr
CodeMStr - avatar