answersLogoWhite

0


Best Answer

swap (int *pa, int *pb) {

*pa ^= *pb;

*pa ^= *pa;

*pa ^= *pb;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program in c using pointers to interchange 2 values without using third variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do we write c program without using swap to interchange values by accessing another variable?

int a,b; a=a+b; b=a-b; a=a-b; that's it simple


What is pointer and where it is used?

A pointer is a variable used to store a memory address. That is, we can use a pointer variable to refer to another variable (including other pointers). Although many variables within a program have names and can be referred to directly by those names, the majority of variables are anonymous; they have no names we can refer to. For instance, every variable declared on the heap is anonymous, every element of an array is anonymous and every node in a list is anonymous. Without pointers there would be no way to refer to these anonymous variables. Moreover, there would be no way to allocate objects on the heap without pointers. Pointers also make it possible to pass addresses into functions. In C, for instance, all arguments to a function are passed by value, however a pointer's value is a memory address thus pointers allow us to use pass by reference semantics. This makes it possible for a function to refer to an object outwith the local scope of the function.


What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


What are void pointers?

They are pointers without type


Can you run java program without applying main method?

yes we can run java program without using main. we can run program by declaring the variable static..


Write a c program to add 2 no without using plus operator?

You can make use of pointers to achieve this.void add( int *a, int *b){(*a) += (*b);}Now if two numbers a and b are given and you need to store the value in variable c, then you would perform:c = a;add(&c,&b);


WAP to interchange the value of two variable without third variable?

Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */ ... *i1 = *i1 ^ *i2; ... *i2 = *i1 ^ *i2; ... *i1 = *i1 ^ *i2; }


Can you write addition of 2 no program without using third variable?

Yes. int a, b; a= 2; b= 3; a= a+b;


How can you devise a way to interchange two variables A and B without using a third variable or register using Exclusive OR?

A = A xor B B = A xor B A = A xor B in C... A^=B; B^=A; A^=B;


Obtain algorithm that corresponds a program for the interchange of two numerical variable values?

In general, to swap two variables A and B with each other, you need a third variable T of the same type. You then perform the sequence T = A, A = B, and B = T. For the special case where A and B are binary types, you can swap them without a temporary variable using a bit-wise exclusive or operator. Using C/C++ syntax, you would use the sequence A ^= B, B ^= A, and A ^= B. For this to succeed, the exclusive or operator (^) must be bitwise. Actually, it is also possible to swap any two arbitrarily typed variables, such as float or object, so long as you can properly do the bitwise exclusive or operation, perhaps by doing typcasts or by playing games with pointers - although any of that is potentially dangerous and not always portable.


Why laser mouse are used?

Because the laser pointers are much easier to use than the ball pointers. The ball pointers are often difficult to move around while the laser pointers can move in any direction without "getting stuck"


what type of variable is visible to every module and the entire program?

If you are talking about a class in Java, a variable encapsulated by a class is called an instance variable b/c everytime you create an object with that class, each object has its own set of the variables declared.