GATE CS 2018 · Question 39 · Programming and Data Structures · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider the following C program:
#include<stdio.h> void fun1(char *s1, char *s2){ char *tmp; tmp = s1; s1 = s2; s2 = tmp; } void fun2(char **s1, char **s2){ char *tmp; tmp = *s1; *s1 = *s2; *s2 = tmp; } int main(){ char *str1 = "Hi", *str2 = "Bye"; fun1(str1, str2); printf("%s %s ", str1, str2); fun2(&str1, &str2); printf("%s %s", str1, str2); return 0; }
The output of the program above is

  1. (A) Hi Bye Bye Hi
  2. (B) Hi Bye Hi Bye
  3. (C) Bye Hi Hi Bye
  4. (D) Bye Hi Bye Hi
Answer

Answer (A)

Answer from the official GATE CS 2018 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes