String Length Calc
String is an array of characters whose last element is '0'. To calculate the length of the string we use a for loop and exclude the '0' element of the array.
/*
http://www.ProbCOMP.com
String is an array of characters whose last element is '\0'. To calculate the length of the string we use a for loop
and exclude the '\0' element of the array.
*/
#include<stdio.h>
void stringlength(char string[])
{
int i;
for(i=0;string[i]!='\0';i++);
printf("Length of string %s is %d",string,i-1);
}
void main()
{
char str[211]="o Compare two arrays we use Arrays equals method.As objects 'equals' method and '==' only checks wether the variables refrences are same or not. Equals method checks the elements of the array and not the refrences." ;
stringlength(str);
}
Download Program


