c - Using pointer to char array, values in that array can be accessed? -


I created PTR as an Potter for an array of 5 characters.

  char (* ptr) [5];   

assigned a four array address to it.

  char arr [5] = {'a', 'b', 'c', 'de'}; Ptr = & amp; Arr 

);

This price does not print.

In my understanding ptr will include the base address of the array, but it actually indicates the memory required for the entire array (like 5 characters). Thus when ptr grows then it goes beyond the sizeof (char) * 5 bytes. So is it not possible to access the array values ​​using this indicator for the array?

To use an element when you want, you must first detrain your pointer, And after which you want the element (which is deferring). That is, you need to:

printf ("\ nvalue:% c", (* ptr) [0]); , which is similar to * (* Ptr) +0)

Note that working with pointer for arrays is not very common in C. Instead, use the first element in the first element in an array, and either deal with a length as a separate element, or at the end of the array, give a senitel value so that one can learn when the array is ended, such as < / P>

  char arr [5] = {'a', 'b', 'c', 'd', 'e', ​​0}; Char * ptr = arr // same four * ptr = & amp; Arr [0] printf ("\ nvalue:% c", ptr [0]);    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -