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
Supine man 90 points

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

int main()
{
    int b = 1;
    fun3(b);
    // b  is still 1 now!
    return 0;   
}

4.5 (2 Votes)
0
3.7
10
Sharptooth 90 points

                                    #include &lt;stdio.h&gt;

void swap(int *x,int *y){
	int t=*x;
	*x=*y;
	*y=t;
}

int main()
{
	int a,b;
	scanf(&quot;%d %d&quot;,&amp;a,&amp;b);
    printf(&quot;Before Swap : %d %d&quot;,a,b);
	swap(&amp;a,&amp;b);
    
	printf(&quot;After Swap : %d %d&quot;,a,b);
}

3.7 (10 Votes)
0
3.6
5
Npcurious 95 points

                                    int main() {
    int b = 1;
    fun(&amp;b);
    // now b = 10;
    return 0;
}

3.6 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to swap pointers c++ how to swap pointers swapping program using pointer in c++ using third variable call by reference inc++ call by reference in c++ code example c++ swap fuction swap fucntion c++ swap in arr with pointer c++ how to swap value using pointer c++ swap fucntion in c++ swap two strings in c++ using pointers c++ swap program use pointer swapping using pointers in c swap in pointer c++ call by value and call by reference Function to swap A and B// using pointers c++ call by value and call by reference in c++ in one example call by reference vs call by reference in c++ swap two numbers using pointers c++ swap address of pointers in c++ c++ swap pointers swap pointer c++ swap using pointers cpp function call by reference why would someone use call by reference in c++ why use call by reference in c++ how to swap values of two pointers c++ call by reference function in c++ call by value and call by reference c++ program swap in C++ function swap with pointers c++ code swap 2 node pointer in cpp swap 2 pointer in cpp swap values using pointers call by reference and call by value in c++ c++ call by reference * swap function c++ swap function in c++ pointer swap function c++ swap function c++ using pointers understanding call by reference in c++ what is call by reference in c++ language c++ function call by reference call by reference cpp when should you use call by reference in c++ what is call by reference in c++ call by reference code in c++ what is call by value and call by reference in c++ call by value and call by reference c++ examples how to call by reference in c++ call by value and call by reference in cpp how to use call by reference in c++ program of call by reference c++ write a program to implement call by reference in c++ C ++ program to swap two numbers using call by value, call by reference and call by pointer c++ function reference argument reference as parameter c++ function by reference c++ function reference as argument function reference as argulent function call by reference c++ calling by reference c++ get the refrence of a method c++ swap values using call by reference in cpp how to reference a function in c++ c++ program for call by reference swap using pointers c++ can we call by reference in c++ call by value and call by reference c++ refrence variable in function call by reference in c++ example call by reference and return by reference in c++ call by value and call by reference in c++ cpp call by reference what is call by reference call by reference in cpp c++ call by reference c++ method reference pass a reference for swap c++ when by reference function call in cpp c++ reference argument make varuiable a reference to function c++ c++ function references call method of refrence of object c++ call by reference and call by value c++ ref input c++ C++ reference parameters in functions c++ reference as parameter how to reference a variable by adress in a function c++ calling a variable with a refeernce to a number c++ c++ reference a variable in a function how to reference to another functionin a function c++ oop c++ reference to function reference argument c++ Reference Arguments in c__ call by reference and call by alias in cpp pass by reference c++ function prototype ways to use syn call by reference in c++ syntax ways to use call by reference in c++ making afunction by reference function by reference in c++ call b y reference in c++ Function Call By Reference In C++ passing value by reference c++ call by reference in c++ examples reference function c++ call by reference c++ how to make reference callin c++ call by reference c++ example c++ accessing reference method call by reference in c++ c++ reference function parameter explain call by reference with example in c++ reference passing c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source