How does c store a double decimal in an 8 bit slot?
#include "stdio.h"
main(){
double x = 123.456;
printf("\n %d - %e \n",sizeof(x),x);
}
outputs:
8 - 23.456
The value of x is correct being 123.456, but the supposedly it is only 8 bits.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s not 8 bits. It’s 8 bytes. And each byte is at least 8 bits (and usually exactly 8 bits).
So it’s probably 8 * 8 = 64-bits for a
double.EDIT:
The
sizeof()operator yields the size of an object in bytes.A “byte” is by definition the size of a
char. (That’s how the C standard defines the word “byte”; it may have different meanings in other contexts.)The number of bits in a byte is specified by the macro
CHAR_BIT, defined in<limits.h>. Almost any system you’re likely to encounter will haveCHAR_BIT == 8, but I understand that some implementations for DSPs (Digital Signal Processors) haveCHAR_BITset to 16 or 32.