C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 7)
Which statement will you add to the following program to ensure that the program outputs "IndiaBIX" on execution?

int main()
    char s[] = "IndiaBIX";
    char t[25];
    char *ps, *pt;
    ps = s;
    pt = t;
        *pt++ = *ps++;

    /* Add a statement here */
    printf("%s\n", t);
    return 0;
Answer: Option
No answer description is available. Let's discuss.
14 comments Page 1 of 2.

Gayathri said:   5 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?

Siri said:   5 years ago
Well said @Bandhan.

Bandna said:   1 decade ago

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.

Shwetha said:   1 decade ago
I inserted the statement pt=ps; and I got the output as IndiaBix.

Please explain this.

Shwetha said:   1 decade ago
When I inserted the statement pt=ps; I got the output as IndiaBix can somebody explain this.

Kirti said:   1 decade ago
But after execution I got IndiaBix without putting *pt='\0';

How is it. Can anyone explain it?

Alyka said:   1 decade ago
*pt contains the memory address for t & pt contains the simple value of t.

Pavan said:   1 decade ago
What is difference between pt='\0' and *pt='\0' ?

Sundar said:   1 decade ago

Thanks for your explanation.

Wikiok said:   1 decade ago
If *pt reach the '\0' element, the while statement goes false, so the last element ('\0') won't be copied. It has to be done manually.

Post your comments here:

Your comments will be displayed after verification.