O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required