C Programming - Strings

Exercise : Strings - Yes / No Questions
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.

2.
For the following statements will arr[3] and ptr[3] fetch the same character?
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
Yes
No
Answer: Option
Explanation:

Yes, both the statements prints the same character 'i'.


3.
Is there any difference between the two statements?
char *ch = "IndiaBIX";
char ch[] = "IndiaBIX";
Yes
No
Answer: Option
Explanation:
In first statement the character pointer ch stores the address of the string "IndiaBIX".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.