CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C program:
#include <stido.h>
void fun 1 (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

A
Hi Bye Hi Bye
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Bye Hi Hi Bye
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Hi Bye Bye Hi
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
Bye Hi Bye Hi
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C Hi Bye Bye Hi

1. fun1(100, 200) "Call By Value"
*s1 = 100; *s2 = 200;
*temp = 100;
*s1 = 200;
*s2 = 100;
Since, fun1 is call by value. So no change to original *str1 and *str2, so printf will print Hi Bye
2. fun2 (&str1, &str2) "Call By Refference"
**s1 = 300; ** s2 = 400;
*temp = 300;
**s1 = 400;
** s2 = 300;
Since, fun2 is call refference. So it will swap the value of str1 and str2 points to "Hi". So printf will point Bye
Hi.
Final output: Hi Bye Bye Hi

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Fear of the Dark
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon