A
arnuld
i am trying to understand arrays and char. Stroustrup says, this a
string literal:
"this is a string literal"
he says it is of type /const char/. he also says, because of keeping
compatibilities with previous definitions of C & C++, it is also a
CHAR POINTER a.k.a /char*/. however it is an error, which can not be
caught at untill runtime, to modify a string literal using such
pointer:
char* name = "Plato" // name is an array of 5 char
name[0] = 'R' // error
tell me whether i am right or wrong
# 1 - p is an array of 6 CHARS (including '\0') , right ?
# 2 - p points to the 1st CHAR, 'P' of name a.ka. "Plato".
# 3 - it is *exactly same as /const char name[] = "Plato"/
#4 - what about /const char*[] = "Plato"/. what does this represent ?
string literal:
"this is a string literal"
he says it is of type /const char/. he also says, because of keeping
compatibilities with previous definitions of C & C++, it is also a
CHAR POINTER a.k.a /char*/. however it is an error, which can not be
caught at untill runtime, to modify a string literal using such
pointer:
char* name = "Plato" // name is an array of 5 char
name[0] = 'R' // error
tell me whether i am right or wrong
# 1 - p is an array of 6 CHARS (including '\0') , right ?
# 2 - p points to the 1st CHAR, 'P' of name a.ka. "Plato".
# 3 - it is *exactly same as /const char name[] = "Plato"/
#4 - what about /const char*[] = "Plato"/. what does this represent ?