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;
}
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.
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");
Ex: strcpy(a,"BIX");
Bava said:
7 years ago
Explain clearly.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers