[Solved] Pointer array and structure in C

[ad_1]

struct a s1={"Hyderabad","Bangalore"}; assigns “Hyderabad” to ch and “Bangalore” to str.

printf("\n%c%c",s1.ch[0],*s1.str); prints the first character of the strings. Since ch is an array, ch[0] represents its first character. Since str is a character pointer, it points to the first character of a string here. So, *s1.str will have value ‘B’

printf("\n%s%s",s1.ch,s1.str); simply prints all characters of both strings.
Fundamentally, ch is equal to &ch[0], the address of the first character in the array. And, str is pointer variable which holds the address of first character of the string literal “Bangalore”.

[ad_2]

solved Pointer array and structure in C