1
I’m studying pointers and came across these statements, but I couldn’t understand it very well. Could you help me? Thank you.
1
I’m studying pointers and came across these statements, but I couldn’t understand it very well. Could you help me? Thank you.
0
Good afternoon,
char (*ptr)[20] is a pointer to a 20-character array...a single pointer that leads to a "string" (char[20]), for simplicity. Ex:
*ptr -> "exemplo
"
Char *ptr[20] is an array of 20 pointers... You have 20 pointers that point to characters. Ex:
*ptr[0] -> e
*ptr[1] -> x
*ptr[2] -> e
*ptr[3] -> m
*ptr[4] -> p
*ptr[5] -> l
*ptr[6] -> o
Browser other questions tagged c array pointer matrix variable-declaration
You are not signed in. Login or sign up in order to post.
char (*ptr)[20]
is a pointer to an array of 20char
andchar *ptr[20]
is an array of 20 pointers forchar
. If with this explanation you were able to understand the difference between one thing and another, then perhaps your difficulty is only reading the instructions in C, I recommend researching the "right-left Rule". On the other hand, if you couldn’t visualize the difference between one thing and another, it would require further study on pointers.– user142154
@v. Santos, put your comment as a response
– zentrunix
@zentrunix, I thought about it, but my problem is that my comment seems incomplete for an answer. And to answer, I didn’t know if I explained the "right-left Rule" or if I was talking about the difference between an array pointer and a pointer array. Now, as the person who asked the question did not express itself and as I liked the answer given by another user, I imagine that there is no longer this need for me to turn the comment into an answer. Anyway, thank you very much.
– user142154