Difference Between char* s = "string"; and char s[] = "string";
This page answers questions like these:
- What’s the difference between char* s = "string"; and char s[] = "string"; in C/C++?
- What’s the difference between char* s; and char s[]; in C/C++?
Related Links:
Difference Between char* and char [] and char s[n]
warning/error: invalid conversion from 'char**' to 'const char**'
Difference Between char* s = "string"; and char s[] = "string";
char* s = "string";
- Create a character pointer s which points to a section of memory containing the string string (including a terminating zero).
- You can change the value of s. i.e. You can make it point to something else.
- sizeof(s) == sizeof(char*).
char s[] = "string";
- Create an array s of 7 characters which contains the string string (including a terminating zero).
- You can’t change the value of s. i.e. You can’t make it point to something else.
- This is similar to “const char* const s = "string";”.
- sizeof(s) == 7 because there are 7 characters in the string string (including the terminating zero).
Related Links:
Difference Between char* and char [] and char s[n]
warning/error: invalid conversion from 'char**' to 'const char**'
Home > C++ / C > Difference Between char* s = "string"; and char s[] = "string";
Tags: char*, char[], char array, struct, class, unbounded array, C++, C
Copyright © HelpDoco.com
difference-between-char-star-equals-string-and-char-array-equals-string.txt
C++-C/difference-between-char-pointer-equals-and-char-array-equals.htm
1