String in C Definition, Syntax and Working

Strings are mainly defined as an array of characters. In simple words it is one dimensional array of characters which is terminated by special character called the null ('/0') character. 

In simple words string is a line of characters, like a word or a sentence. Each character in the string is stored in a specific memory location, and the null character marks the end of the string.



  Syntax:

datatype array_name[size of array];
{
       //block of code
}




  How it works?

char str[]="Hello";

String in C  definition, syntax and working, String in C programming


Above image shows the memory representation of string with their index and memory address.




  Example program of string:



#include<stdio.h>
void main()
{
char str[]="Hello";

printf("%s",str);
}


Above program shows the following output:

String in C  definition, syntax and working, Strings in C programming
 

To explore the exercises and examples of String click Here...

No comments:

Post a Comment

If you have any doubts, please discuss here...👇