Basic String Pointer Syntax

A character string is a type of array, each element containing a specific character and terminating with the \0 character. The code

char name[] = Marc";

requires 5 bytes of memory, since a single character in C requires 1 byte.

In Chapter 9, “Working with Pointers,” you saw that an array's name can also act as a pointer to that array's address. The following code works fine, demonstrating two different uses of the same name array (Figure 11.1):

char name[] = "Marc";
printf ("String: %s \nPointer: %p",
name, name);
Figure 11.1. Character arrays can be printed as strings or as pointers.

The name example adds little ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.