Home » C Programming » Strings

What will be the output of the program? #include int main() { char t; char *p1 = "India", *p2; p2=p1; p1 = "CURIOUSTAB"; printf("%s %s\n", p1, p2); return 0; }

Correct Answer: CURIOUSTAB India

Explanation:

Step 1: char *p1 = "India", *p2; The variable p1 and p2 is declared as an pointer to a character value and p1 is assigned with a value "India".


Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "India".


Step 3: p1 = "CURIOUSTAB"; The p1 is assigned with a string "CURIOUSTAB"


Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.


Hence the output of the program is "CURIOUSTAB India".


← Previous Question Next Question→

More Questions from Strings

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion