c Questions about language data size

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

#include <stdio.h>

int main()
{
    printf("%f", sizeof 3.4 * (double)4);
}

Please tell me in detail why this output value is 32.000000!

c

2022-09-20 10:48

1 Answers

I'm an outsider with C, but I think I can get a rough feeling by testing it like this.

#include <stdio.h>

int main()
{
    printf("%f", size of 3.4); /* What will this be? */ */ printf("\n");
    printf("%f", size of 3.4 * 1); /* Will this be the same as the previous one? */ */ printf("\n");
    printf("%f", size of 3.4 * (int) 1); /* What about this? */ */ printf("\n");
    printf("%f", size of 3.4 * (double) 1); /* What about this? */ */ printf("\n");
    printf("%d", size of 3.4 * (double) 1); /* Oing? What's the difference? */ */ printf("\n");
    printf("%d", size of 3.4 * (int) 1); /* Oing? Does it change if the data types are different? */ */ printf("\n");
    printf("%d", size of 3.4); /* If so, by any chance? */ */ printf("\n");
    printf("%d", size of 3.4 × 4); /* By any chance? */ */ printf("\n");
    printf("%d", size of 3.4 * (double) 4); /* By any chance? */ */ printf("\n");
    printf("%f", size of 3.4 * (double) 4); /* Is formatting of data important when printing??? */ */ printf("\n");
}

It seems highly likely that the questioner did not write that code, but wrote it down from a textbook. In that case, the manner of the "student" is, I guess, looking into it, thinking about what I've learned, and approaching it from various angles. Rather than holding onto the person next to you and asking everything you wrote down.


2022-09-20 10:48

If you have any answers or tips


© 2022 pinfo. All rights reserved.