Skip to main content
C Output Prediction Hard +35 XP

String vs Char

What is the difference between these two declarations?

CRead-only
char a[] = "hello";
char *b = "hello";

What is the output?

Show answer and explanation

Answer: a is modifiable, b points to read-only memory

char[] copies the string to the stack — modifiable. char* points to a string literal in read-only memory — modification is undefined behavior.

Hint: Where is each string stored in memory?

What this challenge tests

Output Prediction in C: strings, pointers, memory.

Related challenges