# Strings — C Programming

Source: https://www.geekswithgeeks.com/en/c/c-strings

> C has no string type — text is a char array ending in a null byte.

## Null-terminated

A C string is a `char` array followed by a hidden `'\0'` (null character) marking its end. `"Hi"` actually stores 3 bytes: `'H'`, `'i'`, `'\0'`.

## Two ways to declare

A string literal or an explicit char array — both are mutable arrays here.

```c
char name[20] = "Alice";     // array, room to grow
char city[]  = "Delhi";      // sized to fit exactly

printf("%s lives in %s\n", name, city);
```

Output:

```
Alice lives in Delhi
```

## %s expects null-termination

`printf("%s", str)` keeps printing bytes until it finds `'\0'`. A char array missing the null byte causes `%s` to read past its bounds.
