C Programming - Pointers - Discussion
Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 7)
7.
Which statement will you add to the following program to ensure that the program outputs "IndiaBIX" on execution?
#include<stdio.h>
int main()
{
char s[] = "IndiaBIX";
char t[25];
char *ps, *pt;
ps = s;
pt = t;
while(*ps)
*pt++ = *ps++;
/* Add a statement here */
printf("%s\n", t);
return 0;
}
Discussion:
14 comments Page 2 of 2.
Shwetha said:
1 decade ago
When I inserted the statement pt=ps; I got the output as IndiaBix can somebody explain this.
Shwetha said:
1 decade ago
I inserted the statement pt=ps; and I got the output as IndiaBix.
Please explain this.
Please explain this.
Bandna said:
1 decade ago
@Shwetha.
As we have assigned pointers corresponding to s and t, while doing ps=pt, it simply copies the whole string s into t.
So you are getting output as "IndiaBix".
We can't do this with array as we can't write s=t.
As we have assigned pointers corresponding to s and t, while doing ps=pt, it simply copies the whole string s into t.
So you are getting output as "IndiaBix".
We can't do this with array as we can't write s=t.
Gayathri said:
6 years ago
In my point of view, While applying operator precedence. It doesn't assign the first letter of the string 'I' to t; Can anyone clarify my doubt?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers