Answers for "swap using pointers c++"

C
1

swap function c++ using pointer

#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;
}
Posted by: Guest on June-03-2021
1

swap using pointers c++

#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);
}
Posted by: Guest on July-12-2021
3

calling by reference c++

int main() {
    int b = 1;
    fun(&b);
    // now b = 10;
    return 0;
}
Posted by: Guest on April-22-2020
0

calling by reference c++

void fun3(int a)
{
    a = 10;
}

int main()
{
    int b = 1;
    fun3(b);
    // b  is still 1 now!
    return 0;   
}
Posted by: Guest on April-22-2020

Code answers related to "C"

Browse Popular Code Answers by Language