Answer to Question #274626 in C++ for khan

Question #274626

What is a data type? Differentiate between array and pointer. Write a program to interchange 2 variables without using the third one.


1
Expert's answer
2021-12-04T01:27:54-0500

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
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment