[quote=“stian24”]Can we have an official answer for the first challenge.
I am not very good and I would like to know if I am ‘out off lunch’ or not?
Thank you.
this is my answer;
float i=1;
printf (“float memory is %zu\n”, sizeof(&i);
return ;
output;
float memory is 8[/quote]
Hello stian24.
When I did Challenge 1, I did the same as ttppdd.
On the top of page 68 you have the code to illustrate uses of sizeof() to find the size of a data type.
Like ttppdd I did the obvious and just used that line but substituted int with float in the brackets.
[code]#include <stdio.h>
int main(int argc, const char * argv[])
{
float f = 17.0; /* we assign the value 17.0 to the float variable f /
printf(“the value of f is %f.\n”, f); / print out the value assigned to float f /
printf(“a float is %zu bytes.\n”, sizeof(float)); / the sizeof() function returns a size value of the float (float) into the token %zu */
}[/code]
I got:[quote]the value of f is 17.000000.
a float is 4 bytes.[/quote]
What you did is interesting and I am trying to figure out exactly what you did here. I copied out your code and overlooking a few typo’s I got the same thing you did:[quote]float memory is 8[/quote]
This is what I think happened with your answer to Challenge 1.
Look at the code on the middle of page 68 again - Line 4 then line 9
int *addressOfI = &i;
. . .
printf("A pointer is %zu bytes\n", sizeof(addressOfI));
In line 4 we assigned the value of &i to addressOfI and in line 9 we printed out the sizeof(addressOfI) which is essentially the value of &i which is a lot like your line of:
Line 9 prints out:[quote]A pointer is 8 bytes[/quote]Just like your line.
I hope I didn’t over explain here and I hope I am correct in what I am saying to you. I’m a noobee like yourself.
I just wish some of the more knowledgable users of this forum like ibex10 reads this and either says yes or NO! You’re wrong! You’re misleading stain24!
[color=#000080]JR[/color]