1,589 views

2 Answers

19 votes
19 votes

Check this, if you have doubt, then comment

2 votes
2 votes

function 1 is also swapping values but locally :

void fun1(char* s1, char* s2){
    char* temp;
    temp = s1;
    s1 = s2;
    s2 = temp;
}

here in stack s1 and s2 will be created but after execution they will distroy

void fun2(char** s1, char** s2){
    char* temp;
    temp = *s1;
    *s1 = *s2;
    *s2 = temp;
}

here s1 and s2 will be local it self but they are poining to pointers and modifications in pointer will be reflected outside also.

 

Related questions

0 votes
0 votes
0 answers
1
himgta asked Sep 4, 2018
386 views
https://gateoverflow.in/204076/gate2018-2Why the answer is A,Why not D?
0 votes
0 votes
0 answers
4
Ram Swaroop asked Jan 3, 2019
638 views
Which of the following functions describe the graph shown in the below figure? (A) y=||x|+1|−2(B) y=||x|−1|−1(C) y=||x|+1|−1(D) y=||x|−1|−1|