The difference here is that
char *s = "Hello world";
will place "Hello world"
in the read-only parts of the memory, and making s
a pointer to that makes any writing operation on this memory illegal.
While doing:
char s[] = "Hello world";
puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. Thus making
s[0] = 'J';
legal.
Related Posts:
- Return char[]/string from a function [duplicate]
- Return char[]/string from a function
- Does C have a string type?
- The difference between char * and char[] [duplicate]
- How does strtok() split the string into tokens in C?
- How to convert an int to string in C?
- What is a string of hexadecimal digits?
- How to convert an int to string in C?
- How to convert a string to integer in C?
- Get a substring of a char* [duplicate]
- char *array and char array[]
- How do I create an array of strings in C?
- Get a substring of a char*
- Expression must be a modifiable L-value
- How do I properly compare strings in C?
- How to convert an int to string in C?
- How to convert a std::string to const char* or char*
- Returning string from C function
- How do I create an array of strings in C?
- Char Comparison in C
- How to check if a string is a number?
- Difference between char* and const char*?
- How can I convert const char* to string and then back to char*?
- How do I lowercase a string in C?
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- Constant pointer vs Pointer to constant
- How do I concatenate const/literal strings in C?
- Reversing a string in C
- How to remove the character at a given index from a string in C?
- Excess elements in char array initializer error
- Split string with delimiters in C
- C char* to int conversion
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- Allocating string with malloc
- Removing trailing newline character from fgets() input
- Allocating char array using malloc
- How to concatenate string and int in C?
- How do I check if a string contains a certain character?
- Convert Char to String in C
- How big can a 64 bit unsigned integer be?
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Implementing Taylor Series for sine and cosine in C
- Working on code to calculate cosine with factorial sum
- How to use execvp()
- How to use execvp() to execute a command
- warning: implicit declaration of function
- warning: implicit declaration of function
- What is *(uint32_t*)?
- pthread_join() and pthread_exit()
- what is Segmentation fault (core dumped)? [duplicate]
- What causes a segmentation fault (core dump) to occur in C?
- uint8_t vs unsigned char
- How to use symbols of extended ASCII table in C?
- Two questions about basic C programs
- What is the difference between ++i and i++?
- Using boolean values in C
- std::string to char*
- What does “collect2: error: ld returned 1 exit status” mean?
- typedef struct vs struct definitions [duplicate]
- How to print in C
- How to convert a char to a String?
- Why should we typedef a struct so often in C?
- How to convert/parse from String to char in java?
- Why should we typedef a struct so often in C?
- What exactly is the difference between “pass by reference” in C and in C++?
- What is the difference between ++i and i++?
- Conversion from string to char – c++
- What can be the reasons of connection refused errors?
- What does “collect2: error: ld returned 1 exit status” mean?
- typedef struct vs struct definitions [duplicate]
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What does the question mark character (‘?’) mean?
- Cannot figure out how to use getchar(); in C
- Floating point exception (core dumped)
- Undefined reference to pthread_create in Linux
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- makefile:4: *** missing separator. Stop
- Stack smashing detected
- Why am I getting “void value not ignored as it ought to be”?
- Correct format specifier for double in printf
- Stack smashing detected
- How do I determine the size of my array in C?
- Why am I getting “void value not ignored as it ought to be”?
- Pointer Arithmetic
- dereferencing pointer to incomplete type
- 1 = false and 0 = true?
- c stack smashing detected
- Openssl : error “self signed certificate in certificate chain”
- What is the difference between C and embedded C?
- What is an unsigned char?
- Undefined reference to pthread_create
- What is the behavior of integer division?
- Convert char to int in C and C++
- How to convert a char array to a string?
- Difference between malloc and calloc?
- What is Bit Masking?
- How do function pointers in C work?
- What causes the Broken Pipe Error?