Jul 25, 2020

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 null ('/0') character.



  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
 



No comments:

Post a Comment

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