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.

Raja said:   7 years ago
Thanks @Avi.

Riswan said:   6 years ago
Thanks to you all.

Fatma mofreh said:   2 years ago
First step:
*s1++ point to I and *s2++ point to B
the first while loop I is replaced by B
so the first output will be Bndia

Second step:
*s1++ point to n and *s2++ point to I
The second while loop n is replaced by I
So the second output will be BIdia.

Third step:
*s1++ point to d and *s2++ point to X
The third while loop d is replaced by X.
So the third output will be BIXia.

Then;
*s2++ point to null so while is ended.
then print \n
(7)


Post your comments here:

Your comments will be displayed after verification.