C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 20)
20.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str1[] = "India";
    char str2[] = "BIX";
    char *s1 = str1, *s2=str2;
    while(*s1++ = *s2++)
        printf("%s", str1);

    printf("\n");
    return 0;
}
IndiaBIX
BndiaBIdiaBIXia
India
(null)
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
43 comments Page 5 of 5.

Joe said:   1 decade ago
Thanks raju.

Shailesh said:   1 decade ago
What raju said on 17th sep was right.

Beyond that I want to tell something is that, while loop is longlasting upto string sizes of both strings are matched i.e => bix=ind.

Now upto this condition there will be 2 increments of both s1, s2.

As at 2nd itteration BI{size)is still less than Ind(size), it will not violate while loop & print BIdia same as raju already told.

Next itteration is last one b'z BIX (srng size) matches with dia(size)& now s2 get assigned to s1 i.e =>BIXia lastly get print.

Vikas said:   1 decade ago
Read the statement of @avi. He give the clear way to define the step wise and clear understand.

I agree to @avi please read the stm of avi I hope you understanding this program.


Post your comments here:

Your comments will be displayed after verification.