+ 1

int main() { printf("int: %d \n", sizeof(int)); printf("float: %d \n", sizeof(float)); printf("double: %d \n", sizeof(d

I am not understanding this the output of this . How can we say size of (char) =1byte(8bits)

21st May 2019, 12:57 PM
Artificial Intelligence
Artificial Intelligence - avatar
6 Respostas
+ 1
What do you don't understand?
21st May 2019, 1:11 PM
Werg Serium
Werg Serium - avatar
+ 1
The function sizeof get the number of bytes of one data-type. For example sizeof(char)=1 byte(8 bits)
21st May 2019, 1:13 PM
Werg Serium
Werg Serium - avatar
+ 1
Print the size of integers, float and double. The size of int is 4 bytes. The size of float is 4 bytes. The size of double is 8 bytes.
21st May 2019, 1:16 PM
Anil
Anil - avatar
0
Char is 1 byte in C because it is specified so in standards. The most probable logic is. the (binary) representation of a char (in standard character set) can fit into 1 byte. At the time of the primary development of C, the most commonly available standards were ASCII and EBCDIC which needed 7 and 8 bit encoding, respectively. So, 1 byte was sufficient to represent the whole character set.
21st May 2019, 1:40 PM
Anil
Anil - avatar
0
Even in some non c standards a char still is 1 byte.
21st May 2019, 1:43 PM
Werg Serium
Werg Serium - avatar
0
Firstly please either paste in the code in the actual post field instead of in the title because the code was cut off or provide us with a link. The sizeof operator returns the size of a type in bytes. - The int type in C is 32 bit so 4 will be displayed (4bytes = 32bits) - Same with the float type - Doubles are just 64 bit floats so obviously it will be double the size (thats also where the name comes from)
21st May 2019, 2:07 PM
TurtleShell
TurtleShell - avatar