C++ simple arrays and pointers question
Posted
by
nashmaniac
on Programmers
See other posts from Programmers
or by nashmaniac
Published on 2012-11-14T05:32:39Z
Indexed on
2012/11/14
11:18 UTC
Read the original article
Hit count: 356
So here's the confusion, let's say I declare an array of characters
char name[3] = "Sam";
and then I declare another array but this time using pointers
char * name = "Sam";
What's the difference between the two? I mean they work the same way in a program. Also how does the latter store the size of the stuff that someone puts in it, in this case 3 characters?
Also how is it different from
char * name = new char[3];
If those three are different where should they be used I mean in what circumstances?
© Programmers or respective owner