Confused about wording of exercise

closed account (jwC5fSEw)
I'm trying to complete an exercise that begins as follows:

Define a float variable. Take its address, cast that address
to an unsigned char, and assign it to an unsigned char
pointer. Using this pointer and [ ], index into the float
variable...


I'm fine up until the last sentence. I don't know what it means by index into the float. Could somebody clarify that?

Also, here's what I have of the program so far, in case something is wrong:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

typedef unsigned char uchar;

int main(){
    float f = 3.14;
    uchar c = uchar(&f);
    uchar* p = &c
    
Essentially you are accessing the individual bytes of the float variable.

In your above code, p[0] is now the first byte of the float, p[1] the second,
and so forth.
Topic archived. No new replies allowed.