Discussion :: Strings
-
What will be the output of the program ?
#include
int main() { char t; char *p1 = "Fresher", *p2; p2=p1; p1 = "GATE"; printf("%s %s\n", p1, p2); return 0; }
Answer : Option B
Explanation :
Step 1: char *p1 = "Fresher", *p2; The variable p1 and p2 is declared as an pointer to a character value and p1 is assigned with a value "Fresher".
Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "Fresher".
Step 3: p1 = "GATE"; The p1 is assigned with a string "GATE"
Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.
Hence the output of the program is "GATE Fresher".
Be The First To Comment