#include<stdio.h> int main() { char str[]={'a','b','c'}; char str1[]={"abc"}; printf("%d",sizeof(str)); printf("%d",sizeof(str1)); getchar(); }
This is giving 3 in case of str and 4 in case of str1 bcz str is "array of character" and str1 is a "string". For understanding this point consider a integer array int arr[] = {1,2,3,4}; then for this sizeof(arr) is 16 means 4*sizeof(int). So in the same way for str in given program it is giving 3*sizeof(char) i.e. 3. sizeof(anyString) = lengthOfString +1 ( +1 for '\0') strlen(anyString) = simple length sizeof(anyArray) = numberofElementPresentInArray*sizeof(dataType) -- *Thanks,* *Vikas Kumar* * * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.