Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Arrays & Pointe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 25444 of 27670
Post > Topic >>

Arrays & Pointers

by arnuld <arnVuld@[EMAIL PROTECTED] > Apr 9, 2008 at 12:34 PM

I am trying hard to understand the Arrays & Pointers relation****p. 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^@[EMAIL PROTECTED]
 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.
 




 3 Posts in Topic:
Arrays & Pointers
arnuld <arnVuld@[EMAIL  2008-04-09 12:34:43 
Re: Arrays & Pointers
Philip Potter <pgp@[EM  2008-04-09 11:51:32 
Re: Arrays & Pointers
David Thompson <dave.t  2008-04-21 01:33:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 22:07:11 CDT 2008.