C Programming - Strings - Discussion

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

int main()
{
    char str[10] = "India";
    str[6] = "BIX";
    printf("%s\n", str);
    return 0;
}
India BIX
BIX
India
Error
Answer: Option
Explanation:

str[6] = "BIX"; - Nonportable pointer conversion.

Discussion:
16 comments Page 1 of 2.

Vishal modi said:   1 decade ago
Nonportable pointer conversion means. ?
(1)

Sindhuja said:   1 decade ago
What is non-portable conversion?
(1)

Suma said:   1 decade ago
I got the warning.

"Assignment makes integer from pointer without a cast". But there is a smooth compilation of the code with the output as "India".
(1)

Mani said:   1 decade ago
When i execute this in gcc compiler it gives the o/p as India.

Pavani said:   1 decade ago
What is nonportable pointers?

George said:   1 decade ago
Hello,

The code in Linux works find and gives "India" as the answer. The reason is this: in the declaration :

char str[10]="India";

// the stringlength is 5 so the
// the string terminator will be at str[5]
// any operation after str[5] will be not
// valid.

Avinash said:   1 decade ago
What is nonportable converter?

Swathi said:   1 decade ago
Can any one explain non-portable conversion ?

Nav said:   1 decade ago
What is nonportable conversion?

Mitkari.sunil said:   1 decade ago
I thought that overwriting in strings is not possible by accessing directly.


Post your comments here:

Your comments will be displayed after verification.