What is a data type? Differentiate between array and pointer. Write a program to interchange 2 variables without using the third one.
What is a data type? - A data type is a classification of data that tells the compiler or interpreter how the programmer intends to use the data.
Differentiate between array and pointer. An array is a memory area in which data of the same type are arranged sequentially, but the pointer is a cell of memory, where is an address to the cell of memory.
Write a program to interchange 2 variables without using the third one.
Write a program to interchange 2 variables without using the third one.
This problem can be solved in a single line
int main(void)
{
int a = 1, b = 2;
// swap
a = a + b - (b = a);
// result: a = 1 + 2 - 1 = 2, b = 1
}
Comments
Leave a comment