Reader small image

You're reading from  Learn C Programming. - Second Edition

Product typeBook
Published inAug 2022
PublisherPackt
ISBN-139781801078450
Edition2nd Edition
Right arrow
Author (1)
Jeff Szuhay
Jeff Szuhay
author image
Jeff Szuhay

Jeff Szuhay is the principal developer at QuarterTil2 which specializes in graphics-rich software chronographs for desktop environments. In his software career of over 35 years, he has engaged in a full range of development activities from systems analysis and systems performance tuning to application design, from initial development through full testing and final delivery. Throughout that time, he has taught computer applications and programming languages at various educational levels from elementary school students to university students, as well as developed and presented professional, on-site training.
Read more about Jeff Szuhay

Right arrow

Declaring and initializing a string

There are several ways to declare and initialize a string. We will explore the various ways to both declare and initialize strings in this section.

String declarations

We can declare a string in several ways. The first way is to declare a character array with a specified size, as follows:

char aString[8];

This creates an array of 8 elements, capable of holding seven characters (don't forget the terminating NUL character).

The next way to declare a string is similar to the first method but instead, we don't specify the size of the array, as follows:

char anotherString[];

This method is not useful unless we initialize anotherString, which we will see in the next section. As you may recall from Chapter 14Understanding Arrays and Pointers, this declaration looks like a pointer in the form of an array declaration. In fact, without initialization, it is.

The last...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learn C Programming. - Second Edition
Published in: Aug 2022Publisher: PacktISBN-13: 9781801078450

Author (1)

author image
Jeff Szuhay

Jeff Szuhay is the principal developer at QuarterTil2 which specializes in graphics-rich software chronographs for desktop environments. In his software career of over 35 years, he has engaged in a full range of development activities from systems analysis and systems performance tuning to application design, from initial development through full testing and final delivery. Throughout that time, he has taught computer applications and programming languages at various educational levels from elementary school students to university students, as well as developed and presented professional, on-site training.
Read more about Jeff Szuhay