C Strings

In C programming, the one-dimensional array of characters are called strings, which is terminated by a null character '\0'.

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', '
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', '
#include<stdio.h>

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

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

   return 0;
}
'}; printf("Tutorials%s\n", name ); return 0; }
Program Output:
TutorialsCloud

Here are few other related articles for you to read:

Scroll Back to Top