Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the difference between char pointer and char array Like(char *p & char p[])
Posted
Comments
Richard MacCutchan 28-Jun-13 4:11am    
Rather than asking questions like this, you would be better off studying a book on C++.
Prashant Gupta 241 28-Jun-13 4:49am    
Ok thanks Richard actually I visit some web sites for these topic but some are contradict and not clear that's why I post my question but for next time I also prefer C++ book first.
Michał Rybiński 4-Jul-13 15:58pm    
You may want revisit Bruce Eckel's Thinking in C++, chapter 3 -> pointers and arrays and chapter 8 (constants) -> Assignment and type checking -> Character array literals.

Basically both define a pointer = address to a block of memory, holding set of chars. The usage makes the difference (do you initialize them with constants in code or not and where in memory during runtime is this kept - determines what you can do in terms of pointer arithmetics and read/write accesss to particular chars)
Last link from ProgramFox solution explains it very nicely.

 
Share this answer
 
Comments
CPallini 28-Jun-13 3:27am    
Good links, my 5.
Thomas Daniels 28-Jun-13 3:29am    
Thank you!
Michał Rybiński 3-Jul-13 14:11pm    
You may want as well revisit Bruce Eckel's Thinking in C++, chapter 3 -> pointers and arrays and chapter 8 (constants) -> Assignment and type checking -> Character array literals.

Basically both define a pointer = address to a block of memory, holding set of chars. The usage makes the difference (do you initialize them with constants in code or not and where in memory during runtime is this kept - determines what you can do in terms of pointer arithmetics and read/write accesss to particular chars)
Last link from ProgramFox explains it very nicely.
Thomas Daniels 4-Jul-13 12:07pm    
Hi,

You posted a comment to my answer, but Prashant Gupta 241 will probably not read it. Post your comment as an answer or as a comment to the question, then Prashant Gupta 241 will get a notification.
Michał Rybiński 4-Jul-13 16:01pm    
:) thx
char *p is a pointer that point to an array, basically 4 bytes in 32 bit-operating system which hold the address of an array.
char[] p is the address of an array, basically the address of the first element in the array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900