String Basics

How do strings work?

  • An array of characters makes up a string. An array stores data of the same type; for instance, an integer array can hold numbers, while a character array can hold a collection of characters. Strings are another term for this character array. A string is a one-dimensional array of characters with a null (‘0’) at the end.

Declaration of Strings:

  • Just like declaring a one-dimensional array, declaring a string is fairly easy. Simply said, we are thinking of it as a variety of characteristics.

The syntax for declaring a string is listed below.

char string_name[string_size];
  • In the syntax above, size is used to specify the string’s length, or the number of characters it may hold. String name is any name supplied to the string variable. Remember that the null character (‘0’), which is used to denote the string’s termination, is an additional terminating character.

String illustration

#include <stdio.h>
int main()
{
    // declare and initialise string
    char str[] = "studentproject";
    printf("%s", str);
    return 0;
}

Output:studentproject

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in