Simple Pointers help!

.
Last edited on
Well, what do you think the answers are?
1. The code invokes undefined behavior because it attempts to access an object through a pointer to unrelated type. (UB per ยง3.10[basic.lval]/10 of C++, C has equivalent clause).

Most modern compilers (with 32-bit integers) actually result in a program that prints 1093318738, which is the decimal equivalent of 0x412ab852, which is the bit pattern of the IEEE 32-bit float 10.67 (hex value 0x1.5570a4p+3)

2. Same problem: the behavior of the program is undefined.

Most modern compilers produce the floating-point value 0x1.3878p-136 which is about 1.401158e-41 decimal, which is shown as 0.000000 by printf's conversion specifier %f

3. no question asked
Last edited on
.
Last edited on
3.
1
2
3
4
5
void MyCopy (int * x, int * y, int n) {
   int i;
   for (i = 0; i < n; i ++)
      y[i] = x[i];
}


or if you wish you can write the function header as void MyCopy (int x[], int y[], int n); (but no one does it that way).
Last edited on
Topic archived. No new replies allowed.