โ† Samsung questions

Difference between string pointer and array

Filed under Samsung

Free read 2 of 3

Points to a string literal residing in read-only data memory. The pointer variable `p` itself can be reassigned to point elsewhere, but modifying the string content causes undefined behavior.

The question

Explain the fundamental differences between a string pointer `char *p = "SAMSUNG";` and a character array `char p[] = "SAMSUNG";` in C.

Constraints

  • Must address memory location, modifiability, and sizeof behavior

Examples

Input
char *p = "SAMSUNG"; vs char p[] = "SAMSUNG";
Output
p[0] = 'X' on char* causes undefined behavior/segfault; on char[] it successfully modifies the stack array.
Why
String literals are typically stored in read-only memory sections, whereas array initialization copies the literal into stack/global modifiable memory.

Approach

  1. Points to a string literal residing in read-only data memory. The pointer variable `p` itself can be reassigned to point elsewhere, but modifying the string content causes undefined behavior.

Tips

  • What they are testing: Check understanding of read-only memory sections versus stack allocation.
  • Common mistake: Assuming `char *` allocates a modifiable buffer for the string contents.

Related Samsung questions

Collected from public candidate posts and coding forums. Updated Nov 2026.