Developer community
0 votes
33.5k views
asked by Expert (13.2k points) 27 41 59 | 33.5k views

1 Answer

0 votes
Program:

#include <stdio.h>

int main() {

int i = 65;

int k = 120;

printf("\n value of i=%d k=%d before swapping", i, k);

i = i ^ k;

k = i ^ k;

i = i ^ k;

printf("\n value of i=%d k=%d after swapping", i, k);

return 0;

}

Explanation:

i = 65; binary equivalent of 65 is 0100 0001

k = 120; binary equivalent of 120 is 0111 1000

i = i^k;

i...0100 0001

k...0111 1000

---------

val of i = 0011 1001

---------

k = i^k

i...0011 1001

k...0111 1000

---------

val of k = 0100 0001 binary equivalent of this is 65

---------(that is the initial value of i)

i = i^k

i...0011 1001

k...0100 0001

---------

val of i = 0111 1000 binary equivalent of this is 120

--------- (that is the initial value of k)
answered by Guru (39.1k points) 10 22 34

Related questions

+1 vote
3 answers
asked by Smita Advisor (7.1k points) 10 23 42 | 6.8k views
0 votes
1 answer
0 votes
1 answer
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users