O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

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

Strings Revisited

A string is an array of characters. Each item in the array is a dereferenced pointer to an element in that array (in this case, a character). The array itself is just a reference to the first in the collection of characters. The difference between an array and a pointer to a piece of memory containing characters is that you generally know the size of the array at compile time.

In other words, you usually declare a sized array of characters as follows:

char my_array[255];

You could equally well define a pointer to the start of a block of memory containing an undisclosed number of characters:

char * my_array; // Or, char my_array[];

Think back to the main function and recall that it is generally defined as:

int main ( int argc, ...

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