C Programming language-C Strings

C Strings

In C programming, the one-dimensional array of characters are called C Strings, which is terminated by the null string ‘\0’.

String Declaration in C

In C programming, we can declare C in two methods such as,

Example:

The string can be declared through an array of characters,
char name[5];
The string can be declared through pointers,
char *name;
String Initialization in C

The string can be initialized in C when it has declared.

Example 1:
char name[6] = {‘S’, ‘p’, ‘a’, ‘r’,’k’, ‘\0’}
Example 2:
char name[] = “Spark”;
The memory representation of the above-defined string in C is

namespark\0

012345

Example Program:

#include<stdio.h>

int main ()
{
   char name[6] = {'S', 'p', 'a', 'r', 'k', '\0'};

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

   return 0;
}
Output:
Spark Databox