Monday, 8 December 2014

program to view differences between length of string and size of string
#include<stdio.h>
main()
{
int size1,size2,size3,len1,len2,len3;
char str1[]={'V','E','0','T','O','R','\0'};
char str2[]={'X','Y','Z','\0'};
char str3[]="vector";
printf("str2=%s\n",str2);
size1=sizeof(str1);
size2=sizeof(str2);
size3=sizeof(str3);
printf("size1=%d size2=%d size3=%d\n",size1,size2,size3);
for(len1=0;str1[len1];len1++)
;
printf("length1=%d\n",len1);
for(len2=0;str2[len2];len2++)
;
printf("length2=%d\n",len2);
for(len3=0;str3[len3];len3++)
;
printf("length3=%d\n",len3);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ ./a.out
str2=XYZ
size1=7 size2=4 size3=7
length1=6
length2=3
length3=6