Gate2018 cs Q60

0. Consider the following C program:
#include
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

  • Option : A
  • Explanation :
    fun1(char *s1, char *s2)
    function scope is local, so the value changed So the affect actual parameters. SO the values will be ‘Hi Bye’.
    fun2(char **s1, char **s2)
    In this function value is pointer to pointer, so it changes pointer of the actual value. So values will be ‘Bye Hi’
Cancel reply

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


Cancel reply

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