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.


What can an integer variable store?

An integer variable can store whole numbers, which can be positive, negative, or zero. The specific range of values it can hold depends on the programming language and the size of the integer type used (e.g., 32-bit or 64-bit). Integers are often used for counting, indexing, and performing arithmetic operations. They do not store fractional or decimal values, which are typically handled by floating-point variables.


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.


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 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.


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 the range of integer constants?

The range of integer constants typically refers to the set of values that an integer can represent within a specific programming language or system. This range is determined by the number of bits used to store the integer; for example, a 32-bit signed integer can represent values from -2,147,483,648 to 2,147,483,647. In contrast, an unsigned 32-bit integer can represent values from 0 to 4,294,967,295. Different systems may have varying limits depending on their architecture and data types.