What's difference between char s[] and char *s in C? Last Updated : 04 Jun, 2025 Comments Improve Suggest changes Like Article Like Report Consider below two statements in C. What is the difference between the two? char s[] = "geeksquiz"; char *s = "geeksquiz";Below are the key differences:Aspectchar a[10] = "geek";char *p = "geek";Naturea is an arrayp is a pointer variableSizesizeof(a) = 10 bytes (32-bit Systems)sizeof(p) = 4 bytes (32-bit Systems)Address Comparisona and &a are the samep and &p are not the sameMemory Location"geek" is stored in the stack section of memoryp is stored in stack, but "geek" is stored in code sectionReassignmenta = "hello"; → InvalidReason: a is an address and cannot be reassigned to another address (string constant)p = "india"; → ValidIncrementa++ → Invalidp++ → ValidModificationa[0] = 'b'; → Validp[0] = 'k'; → InvalidReason: Code section is read-onlyThe statements 'char s[] = "geeksquiz"' creates a character array which is like any other array and we can do all array operations. The only special thing about this array is, although we have initialized it with 9 elements, its size is 10 (Compiler automatically adds '\0') C #include <stdio.h> int main() { char s[] = "geeksquiz"; printf("%lu", sizeof(s)); s[0] = 'j'; printf("\n%s", s); return 0; } Output10 jeeksquizThe statement 'char *s = "geeksquiz"' creates a string literal. The string literal is stored in the read-only part of memory by most of the compilers. The C and C++ standards say that string literals have static storage duration, any attempt at modifying them gives undefined behavior. s is just a pointer and like any other pointer stores address of string literal. C #include <stdio.h> int main() { char *s = "geeksquiz"; printf("%lu", sizeof(s)); // Uncommenting below line would cause undefined behaviour // (Caused segmentation fault on gcc) // s[0] = 'j'; return 0; } Output8Running above program may generate a warning also "warning: deprecated conversion from string constant to ‘char*’". This warning occurs because s is not a const pointer, but stores address of the read-only location. The warning can be avoided by the pointer to const. C #include <stdio.h> int main() { const char *s = "geeksquiz"; printf("%lu", sizeof(s)); return 0; } Output8 Comment More infoAdvertise with us Next Article What's difference between char s[] and char *s in C? K kartik Follow Improve Article Tags : Difference Between C Language cpp-string C Array and String Similar Reads What is the difference between "char a" and "char a[1]"? Question Source: Aricent Interview Although both expressions can be used to create a variable to store one character, there are following differences. 1) "char a" represents a character variable and "char a[1]" represents a char array of size 1. 2) If we print value of char a, we get ASCII value of 1 min read Difference between strncmp() and strcmp in C/C++ The basic difference between these two are : strcmp compares both the strings till null-character of either string comes whereas strncmp compares at most num characters of both strings. But if num is equal to the length of either string than strncmp behaves similar to strcmp.Problem with strcmp func 3 min read Difference between int *a and int **a in C In C, the declarations int *a and int **a represent two different concepts related to pointers. Pointers play a fundamental role in memory management and data manipulation in C programming so it is important to have a clear understanding of them. What does int * means? This declares a pointer to an 3 min read Difference between strlen() and sizeof() for string in C sizeof() Sizeof operator is a compile time unary operator which can be used to compute the size of its operand. The result of sizeof is of unsigned integral type which is usually denoted by size_t.sizeof can be applied to any data-type, including primitive types such as integer and floating-point ty 2 min read Difference between int* p() and int (*p)()? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, a pointer must be declare before storing any variable address. The general form of a pointer variable declaration is: Syntax: type *var_name; Here, type 2 min read Like