String as an Array in C
In C Language, String is an array of Char which is terminated by ‘\0’ (NULL).
#include<stdio.h>
#include<conio.h>
void main()
{
char nm[12];//String
int i;
clrscr();
printf("\nEnter Name :");
scanf("%s",&nm);
i=0;
while(nm[i]!= '\0') //NULL
{
printf("\nAt nm[%d] char is %c",i,nm[i]);
i++;
}
printf("\nLength of String %d",i);
getch();
}
When you iterate the loop up to NULL character then I will be the length of the String.