answersLogoWhite

0

t = a; a = b; b = t; // t is a third integer variable (swap variable)

But here's a way without a swap variable, given as as a macro in C:

#define SWAP(a,b) { if (a!=b) { a^=b; b^=a; a^=b; }} // Swap macro by XOR

Once you define it, you can say swap(x,y) to swap x and y. The numbers kind of flow through each other and end up swapped.

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

If a variable has possible values -2 6 and 17 then this variable is?

If a variable has possible values -2 6 and 17 then this variable is an Integer.


What is difference between an integer variable and floting point variable?

The set of the possible values.


What is a variable in C language?

variable which is used to specify the values and also we can that values through the variable name


A random variable is said to be discrete if?

It can take only a finite number of values. These need not be integer values.


How do you decide which integer type to use in c language?

By the range of values you wish to represent.


How can you check if a variable is a string or an integer in PHP?

Integers - The "is_int()" function can be used to check if a variable is has an integer for its value. ---- is_int($variable); // Returns true if $variable is an integer - otherwise false ---- Numeric Strings - Numeric strings are strings with numbers (or things that count as numbers) in them. Numeric-string variables are not integer variables. Numeric-string variables are passed on through forms, instead of integer variables - if you were wondering. Check form values using string formats, and not integer formats. The "is_numeric()" function can be used to check if a variable is a string with numbers - and only numbers - in it (except things that add up to be numbers). ---- is_numeric($variable); // Returns true if $variable is a string, and only contains numbers (broadly speaking) - false otherwise ---- Strings - String values are just text, basically. String variables can contain integers, but that does not make it an integer-type variable - it makes it a numeric string variable. The "is_string" function can be used to check if a variable contains the value of a string. ---- is_string($variable); // Returns true if $variable is a string - false otherwise


How do you solve a problem with an integer and a variable when the variable is not in place of a number?

A variable must be in place of a number, or representing a range of possible values. Otherwise, it is a constant and so yous imply replace it with the value of that constant.


How many values can store a variable at a time?

The number of values a variable can store at a time depends on the data type of the variable. For example, a variable of type int (integer) in many programming languages can store a single integer value at a time. Similarly, a variable of type float (floating-point number) can store a single floating-point value. Other data types like arrays or lists can store multiple values at a time. The capacity of a variable to store values is determined by its data type and memory allocation.


What does data types mean?

A particular kind of data item, as defined by the values it can take, the programming language used, or the operations that can be performed on it. I hope this has been useful to you.


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 are characters in c language?

1. integer values between 0 and 255 (if unsigned) 2. integer values between -128 and 127 (if signed) 3. letters, digits, symbols like a-zA-Z0-9;,.?: etc


To evaluate a variable expression you must do what to values for the variable?

You must substitute values for the variable.