C Programming - Strings - Discussion

1. 

Will the program compile successfully?

#include<stdio.h>

int main()
{
    char a[] = "India";
    char *p = "BIX";
    a = "BIX";
    p = "India";
    printf("%s %s\n", a, p);
    return 0;
}

[A]. Yes
[B]. No

Answer: Option B

Explanation:

Because we can assign a new string to a pointer but not to an array a.

Mallikarjun Hangargi said: (Oct 25, 2010)  
Instead we can use strcpy() function;

Ex: strcpy(a,"BIX");

Manikandan said: (May 28, 2017)  
This because the pointer is non-const string but array contain const string but strcpy() is an inbuilt function which allows array's content to get replaced with another content.

Bava said: (Feb 7, 2019)  
Explain clearly.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.