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;
}
Discussion:
22 comments Page 3 of 3.
Pawan said:
9 years ago
According to me here,
while(*t=*s)
*t++ = *s++;
Here first *t=*s will take the value, after entering into the while it is again going to overwrite the value and then do the post-increment of the pointer. Now the pointers got next character location and again the same repeats till the while fails because of the array *t comes with the null character.
while(*t=*s)
*t++ = *s++;
Here first *t=*s will take the value, after entering into the while it is again going to overwrite the value and then do the post-increment of the pointer. Now the pointers got next character location and again the same repeats till the while fails because of the array *t comes with the null character.
(2)
Varsha said:
8 years ago
You are right, Thank you @Pawan.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers