C Programming - Strings - Discussion

Discussion Forum : Strings - Yes / No Questions (Q.No. 1)
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;
}
Yes
No
Answer: Option
Explanation:
Because we can assign a new string to a pointer but not to an array a.
Discussion:
3 comments Page 1 of 1.

Bava said:   7 years ago
Explain clearly.

Manikandan said:   8 years ago
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.

Mallikarjun hangargi said:   1 decade ago
Instead we can use strcpy() function;

Ex: strcpy(a,"BIX");

Post your comments here:

Your comments will be displayed after verification.