@sachin..thnx for explanation..got it..plz tell #include<stdio.h>
int main() { char str[]={'a','b','c'}; char str1[]={"abc"}; printf("%d",sizeof(str)); printf("%d",sizeof(str1)); getchar(); } why str has size 3 and str1 has 4.......NUll should also come after c of str???then y 3?? On Mon, Oct 8, 2012 at 5:07 PM, Sachin <sachin.maheshw...@gmail.com> wrote: > @rahul According to C specification, half filled array will be filled with > value 0. In your example you are setting str[0] as 'g' and str[1] as 'k'. > So the compiler sets str[2....9] as 0. So you string str becomes > {'g', 'k', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'} > > Confusion is arising from the fact that you have created an array of 10 > elements. > > To answer you original question "gk" is inherently {'g', 'k', '\0'} and > has size 3 while {'g', 'k'} has size 2. > > Regards, > Sachin > > > On Saturday, October 6, 2012 9:34:30 PM UTC+5:30, rahul sharma wrote: > >> #include<stdio.h> >> >> >> int main() >> { >> char str[10]={'g','k'}; >> char str1[10]="gh"; >> int i; >> for(i=0;str1[i]!=NULL;i++) >> printf("%c",str[i]); >> getchar(); >> } >> >> NUll is there in character array also...make clear me... >> >> On Sat, Oct 6, 2012 at 9:22 PM, rahul sharma <rahul2...@gmail.com> wrote: >> >>> int main() >>> { >>> char str[10]={'g','k'}; >>> char str1[10]="gh"; >>> >>> >>> printf("%s",str); >>> printf("%s",str1); >>> getchar(); >>> } >>> then how does this work??? >>> str printing gk...then NULL is automatically appended in this also...plz >>> tell >>> >>> >>> On Sat, Oct 6, 2012 at 6:33 PM, Rathish Kannan <rathis...@gmail.com>wrote: >>> >>>> For string, C appends '\0' internally. hence sizeof(str) returned the >>>> value 3. >>>> str1 is char array with two character. hence sizeof(str1) returned the >>>> value 2. >>>> >>>> -- RK :) >>>> >>>> >>>> On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma <rahul2...@gmail.com>wrote: >>>> >>>>> char str[]="ab"; >>>>> char str1[]={'a','b'}; >>>>> >>>>> sizeof(str) ...o/p is 3 >>>>> sizeof(str1)....o/p is 2.. >>>>> >>>>> Why so???? >>>>> plz explain... >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to algo...@googlegroups.com. >>>>> To unsubscribe from this group, send email to algogeeks+...@** >>>>> googlegroups.com. >>>>> >>>>> For more options, visit this group at http://groups.google.com/** >>>>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en> >>>>> . >>>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algo...@googlegroups.com. >>>> To unsubscribe from this group, send email to algogeeks+...@** >>>> googlegroups.com. >>>> >>>> For more options, visit this group at http://groups.google.com/** >>>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>. >>>> >>> >>> >> -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/algogeeks/-/65EsWyTnMlEJ. > > 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. > -- 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.