Hello, I have a question about the 1D arrangement of mistakes

Asked 2 years ago, Updated 2 years ago, 93 views

#include <stdio.h>

void main()
{    
    double i, sale[5] = {157, 209, 251, 312, 500};
    for (i = 0; i < 5; i++) {
        printf("\n address:%u sale[%d]=%d", &sale[i], i, sale[i]);
    }
}

This...

I want to put it this way.

I want to check the logical and physical order of the real numbers float and double.

What should I change to pick a mistake in that code?

array float double

2022-09-20 17:27

1 Answers

#include <stdio.h>

int main(){
    int i;
    double sale[5] = {157, 209, 251, 312, 500};
    for (i = 0; i < 5; i++) {
        printf("\n address:%u sale[%d]=%f", &sale[i], i, sale[i]);
    }

    return 0;
}

The format string %d in the printf function represents an integer. If you change it to %f, it'll come out well.

Looking at the values of -99, -47, etc., it seems that the overflow is coming out because it has changed to the byte type. I don't know why this part turned into bye.


2022-09-20 17:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.