In C programming, one-dimensional arrays of characters are called strings, terminated by a null character '\0'. In this tutorial, you will learn about C Strings, how it works in the C language and how you can use them in your C program.



Strings Declaration in C

There are two ways to declare a string in C programming:

Example:

Through an array of characters.

char name[6];

Through pointers.

char *name;

Strings Initialization in C

Example:

char name[6] = {'C', 'l', 'o', 'u', 'd', '\0'};

or

char name[] = "Cloud";

Memory Representation of Above Defined String in C

c-strings

Example:

#include<stdio.h>

int main ()
{
    char name[6] = {'C', 'l', 'o', 'u', 'd', '\0'};

    printf("Tutorials%s\n", name );

    return 0;
}

Program Output:

TutorialsCloud


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram