C Programming - Strings - Discussion


What will be the output of the program ?


int main()
    char str = "IndiaBIX";
    printf("%s\n", str);
    return 0;

[A]. Error
[B]. IndiaBIX
[C]. Base address of str
[D]. No output

Answer: Option A


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".

Sudheer said: (Aug 16, 2013)  
What do we mean by segmentation fault?

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

Yuganya said: (Sep 25, 2013)  
What is meant by "Non portable pointer conversion" error?

Rishi said: (Nov 20, 2016)  
I tried it both ways i.e by using *str, str[ ] it's not working.

Someone help me to get this.

Syed Ahmed said: (Dec 21, 2016)  

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

Allauddin Pirjade said: (Jan 7, 2018)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.