A
arnuld
I am trying hard to understand the Arrays & Pointers relationship. Tell
me if I am wrong:
char a[] = "blah blah";
char *p = "blah blah";
----------------------
ARRAY | | | | | |
| | | | | |
----------------------
----------------------
p ---- ----- ----|-> | | | | |
| | | | | |
----------------------
this is the difference between an array and pointer to a string. Arrays &
Pointers are *not* interchangeable, they are *not* equal. When we pass an
array to a function, we are faking a pointer-phenomenon in reality because
arrays can not be passed to functions, when we pass an array as a
parameter to a function, it immediately decays into a pointer to its 1st
element and then we can access the subsequent elements using
pointer-arithmetic. That's all we got about Arrays and Pointers relation.
Except this they have nothing in common.
I am still not able to understand a program I wrote sometime ago, using th
example code I have shown above for a[] and *p. when I printed the array
using pointer-arithmetic, it printed all the elements but when I tried to
print the elements of that string using *p , it printed this:
^a^d^@
3 4
I did not understand it, it did not even print the one single element of
the string. I can't recall the exact code but it was a pointer to a string
and it printed exactly that output.
-- http://lispmachine.wordpress.com/
Please remove capital 'V's when you reply to me via e-mail.
me if I am wrong:
char a[] = "blah blah";
char *p = "blah blah";
----------------------
ARRAY | | | | | |
| | | | | |
----------------------
----------------------
p ---- ----- ----|-> | | | | |
| | | | | |
----------------------
this is the difference between an array and pointer to a string. Arrays &
Pointers are *not* interchangeable, they are *not* equal. When we pass an
array to a function, we are faking a pointer-phenomenon in reality because
arrays can not be passed to functions, when we pass an array as a
parameter to a function, it immediately decays into a pointer to its 1st
element and then we can access the subsequent elements using
pointer-arithmetic. That's all we got about Arrays and Pointers relation.
Except this they have nothing in common.
I am still not able to understand a program I wrote sometime ago, using th
example code I have shown above for a[] and *p. when I printed the array
using pointer-arithmetic, it printed all the elements but when I tried to
print the elements of that string using *p , it printed this:
^a^d^@
3 4
I did not understand it, it did not even print the one single element of
the string. I can't recall the exact code but it was a pointer to a string
and it printed exactly that output.
-- http://lispmachine.wordpress.com/
Please remove capital 'V's when you reply to me via e-mail.