Course Content

Course Content


  • STEP 1: START.
  • STEP 2: ENTER x, y.
  • STEP 3: PRINT x, y.
  • STEP 4: x = x + y.
  • STEP 5: y= x - y.
  • STEP 6: x =x - y.
  • STEP 7: PRINT x, y.
  • STEP 8: END.

To swap two variables, use the bitwise XOR operator. When two integers x and y are XORed, the result is a number with all bits set to 1 wherever the bits of x and y differ. For instance, the XOR of 10 (in Binary 1010) and 5 (in Binary 0101) is 1111, while the XOR of 7 (0111) and 5 (0101) is 1111. (0010).

This is a question that most of us have asked at some point in our lives. However, it is not easy to answer because there are so many possibilities. C language uses the two-operand instruction for swapping the two numbers in the expression on the left and right side of the equals sign. This is called a swap instruction. When C language executes an assignment statement, it first stores an old value in memory and then assigns a new value to the old memory location. This process is called de-referencing.

If you have a=1 and b=2, you are swapping. If you do a=2 and b=1 in any way, this number will be swapped. You can swap numbers with or without the use of variables!

Swapping two numbers in C can have consequences on the functionality of the program. For example, if you swap two numbers, it can cause an overflow error or undefined behavior.

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere