C Programming - Strings - Discussion

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

int main()
{
    char str = "IndiaBIX";
    printf("%s\n", str);
    return 0;
}
Error
IndiaBIX
Base address of str
No output
Answer: Option
Explanation:

The line char str = "IndiaBIX"; generates "Non portable pointer conversion" error.

To eliminate the error, we have to change the above line to

char *str = "IndiaBIX"; (or) char str[] = "IndiaBIX";

Then it prints "IndiaBIX".

Discussion:
5 comments Page 1 of 1.

Allauddin Pirjade said:   7 years ago
Char data types takes only one or two characters that's why it giving error.

If we use char* or char[ ] then it prints whole string.

Syed Ahmed said:   8 years ago
@Rishi.

It should have worked. Show your code, we can debug it.

Rishi said:   9 years ago
I tried it both ways i.e by using *str, str[ ] it's not working.

Someone help me to get this.

Yuganya said:   1 decade ago
What is meant by "Non portable pointer conversion" error?

Sudheer said:   1 decade ago
What do we mean by segmentation fault?

And why dev c++ prints NULL for this problem.

Post your comments here:

Your comments will be displayed after verification.