Question 2972 – 2013 December UGC NET Paper 1
February 5, 2024
Question 14378 – DSSSB PGT 2018 Female
February 5, 2024
Question 2972 – 2013 December UGC NET Paper 1
February 5, 2024
Question 14378 – DSSSB PGT 2018 Female
February 5, 2024

Question 7868 – Programming

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 **s2, 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

Correct Answer: A

Question 5 Explanation: 
The first call to the function ‘func1(str1, str2);’ is call by value.

Hence, any change in the formal parameters are NOT reflected in actual parameters.
Hence, str1 points at “hi” and str2 points at “bye”.
The second call to the function ‘func2(&str1, &str2);’ is call by reference.
Hence, any change in formal parameters are reflected in actual parameters.
Hence, str1 now points at “bye” and str2 points at “hi”.
Hence answer is “hi bye bye hi”.
A
Hi Bye Bye Hi
B
Hi Bye Hi Bye
C
Bye Hi Hi Bye
D
Bye Hi Bye Hi

Leave a Reply

Your email address will not be published. Required fields are marked *