: what is the difference between char name[] and char *name:
: can you please explain me with an example?
:
it depends how u r using name[] and *name; in the following context, these two are same:
char name[] = "First name";
--------------------------
char *name = "First name";
in the declaration in function prototype, these two are also same:
void function(char *name);
---------------------------
void function(char name[]);
however, usually when char name[] is used, it means a static array, whose address cannot be changed. but when char *name is used, it can be point to any valid memory of the same type (ie, char here). look at the following code, where u cannot use [] and * interchangeably:
char name[] = "The string";
char *ptr;
for (ptr = name; *ptr; ptr++)
cout << *ptr << '-';
also, u cannot use pointer arithmatic with name, where as it is possible with ptr (as u see, ptr++).
~Donotalo()