Strings in C

Strings in C

Array of characters in C Language are called Strings. Null character also has a role in C language. A string is terminated by a null character i.e. \0. In this lesson we will learn how to work with Strings in C programming.

Let’s first see what we meant by strings. The following is a string,

We will now learn how to declare and initialize the above string in C programming,

We haven’t added the null character above, since the compiler adds on its own. In addition, we haven’t added size, since it is optional. Let’s see the entire example,

The following is the output,

Strings in C Language

You can also declare and initialize the above string like the following, with an extra space for null character and size in square brackets,

Above, we added an extra size for the array to hold null character.

Now let’s see another example of a string,

The declaration and initialization of above string,

You may have noticed the following in the above declaration,

  • We have not added the size, since it is optional.
  • A null character is added at the end.

Let’s see the entire example,

The following is the output,

String with null character in C Language

The array structure looks like the following with characters,

Array of characters with index in C Programming

In this lesson we learned how to work with Strings in C programming.

Arrays in C Programming
C Online Quiz
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create free tutorials for all.

No Comments

Post A Comment