char pointer v.s. char array
This note is to compare difference between pointer and array in C.[1]
- const character pointer
const char* s = "hello";
- Allocation Type:
static
- Read/Write:
Read-Only
- Storage Location:
Code Segment
- Memory Usage: 6 (5 bytes + 1 '\0')
- character pointer with initialized string
char* s = "hello";
- Allocation Type:
static
- Read/Write:
Read-Only
- Storage Location:
Code Segment
- Memory Usage: 6 (5 bytes + 1'\0')
- character pointer with string
char* s = malloc(5);
- Allocation Type:
dynamic
- Read/Write:
Read-Write
- Storage Location:
Heap
- Memory Usage: amount passed by malloc
- character array by given string
char s[] = "hello";
- Allocation Type:
static
- Read/Write:
Read-Write
- Storage Location:
Stack
- Memory Usage: 6 (5 bytes + 1'\0')
- character array by given fixed size
char s[10] = "hello";
- Allocation Type:
static
- Read/Write:
Read-Write
- Storage Location:
Data Segment
- Memory Usage: 10