GATE CS 2018 (Forenoon) — Question 39

Programming in CPointers, Multi-Dimensional Arrays, StructuresMCQ2 marks · −2/3 if wrongMedium

Consider the following C program:
c
1#include<stdio.h>
2void fun1(char *s1, char *s2){
3    char *tmp;
4    tmp = s1;
5    s1 = s2;
6    s2 = tmp;
7}
8void fun2(char **s1, char **s2){
9    char *tmp;
10    tmp = *s1;
11    *s1 = *s2;
12    *s2 = tmp;
13}
14int main(){
15    char *str1 = "Hi", *str2 = "Bye";
16    fun1(str1, str2); printf("%s %s ", str1, str2);
17    fun2(&str1, &str2); printf("%s %s", str1, str2);
18    return 0;
19}
20
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
Practise the full 2018-FN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAPractise this subject in the exam simulatorTimed, GATE-style tests with analytics that find your weak topics.
Practise more on Pointers, Multi-Dimensional Arrays, StructuresTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group