C Programming - Strings - Discussion

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

int main()
{
    char str1[] = "Hello";
    char str2[10];
    char *t, *s;
    s = str1;
    t = str2;
    while(*t=*s)
        *t++ = *s++;
    printf("%s\n", str2);
    return 0;
}
Hello
HelloHello
No output
ello
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 3 of 3.

Nikhil said:   1 decade ago
In the loop, it is always a true condition hence it will never come out of the loop so no output

Kavyashree said:   1 decade ago
Here s will points to the beginig of string str1.

And t will points to the begining address of string str2.

In while loop we are copying the elements from str1 to str2 using pointers s and t untill end of string is reached.


Post your comments here:

Your comments will be displayed after verification.