Yes / No Questions

Question 1 :

Will the program compile successfully?

#include < stdio.h >
int main()
{
    char a[] = "India";
    char *p = "PARINAM";
    a = "PARINAM";
    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.


Question 2 :

For the following statements will arr[3] and ptr[3] fetch the same character?

char arr[] = "IndiaPARINAM";
char *ptr = "IndiaPARINAM";


A). Yes
B). No
Answer : Option A

Explanation :

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


Question 3 :

Is there any difference between the two statements?

char *ch = "IndiaPARINAM";
char ch[] = "IndiaPARINAM";


A). Yes
B). No
Answer : Option A

Explanation :

In first statement the character pointer ch stores the address of the string "IndiaPARINAM".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.