swap using pointers c++
#include <stdio.h>
void SwapValue(int &a, int &b) {
int t = a;
a = b;
b = t;
}
int main() {
int a, b;
printf("Enter value of a : ");
scanf("%d", &a);
printf("\nEnter value of b : ");
scanf("%d", &b);
SwapValue(a, b);
printf("\nAfter swapping, the values are: a = %d, b = %d", a, b);
return 0;
}
4.5
2
void fun3(int a)
{
a = 10;
}
int main()
{
int b = 1;
fun3(b);
// b is still 1 now!
return 0;
}
Thank you!
2
0
3.7
10
#include <stdio.h>
void swap(int *x,int *y){
int t=*x;
*x=*y;
*y=t;
}
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("Before Swap : %d %d",a,b);
swap(&a,&b);
printf("After Swap : %d %d",a,b);
}
Thank you!
10
0
3.6
5
int main() {
int b = 1;
fun(&b);
// now b = 10;
return 0;
}
Thank you!
5
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
-
-
-
-
-
-