1 Attachment(s)
Trouble With Pointer Arithmetic
I’ve attached two short c programs which I’ll be referencing
in the text below, if you have a moment please ctex.zip find in this
LINK>> WeTransfer
Attachment also here:
Attachment 15458
It contains the files:
listing1.6.2Indirection.c and listing1.6.1.c
Regarding listing1.6.2Indirection.c
If ptr is the name given to a pointer
which is pointing to the beginning of the buffer array
i.e. buffer[0].
And I’ve set buffer[0] to 435.
why does:
printf(“ %f \n”, ptr);
print 0.00 to the console? Im expecting it to print 435?
In fact I was initially expecting some long random value
because ptr is just a variable name?
whats adds to my confusion is
also because…
In listing1.6.1.c
ptr is pointing to the last element in buffer[1024];
but when I say:
buffer[1003] = 500;
printf(“%f \n”, ptr);
the console prints 500?
This is a very confusing result when ptr is
pointing to the last element of buffer here.
When I’ve changed a different element althogether?
What am I not getting ?
Many Many thanks