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 3 of 5.

Nitin said:   1 decade ago
@(ramu and nishu)::it works.raju has explained it well ,read his explanation once more you will get the idea.each assignment comes to TRUE and that leads to the PRINT.

Siddu said:   1 decade ago
But assignment operator is have less precedence than ++ and *.

So first post increment or dereferencing should be done, later assignment should take place?

Raju said:   2 decades ago
The 1st letter of *s2++ is BIX = 'B'.

'B' is assigned to the 1st letter of S1 so it becomes Bndia.

Rest are follows the same way.

Ramu kaka said:   1 decade ago
You all wrong see in while statement operator '=' is assignment operator not a equality operator, so s2 is assigned to s1.

Manish said:   7 years ago
I think while need a condition but there is '='assignment operator that can only assign the value so. It couldn't run.

Lijina said:   1 decade ago
str1="india" str2="bix"
so
first->bndia
second->bidia
third->bixia

Rohan said:   7 years ago
You are absolutely right @Sowmya.

str1 value must be "India" as output.

Aditi said:   1 decade ago
None of the explanations are clear. Please give some more description. Anyone?

Manoj said:   1 decade ago
while(*s1++ = *s2++)

What is condition does?

Sandhya said:   9 years ago
I did not understand this, tell me clarity.


Post your comments here:

Your comments will be displayed after verification.