Single Choice Easy

QWrite a function to swaps the values of two integers.

ID: #1367 Fundamentals of C Language 1,740 views
Question Info
#1367Q ID
EasyDifficulty
Fundamentals of C LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A No solution exist.
  • B Solution need 2 extra variables
  • C Solution exist without any extra variables
  • D Solution need 1 extra variable
Correct Answer

Explanation

Solution c Solution exist without any extra variables
1.
void swap(int a, int b)
{
int c;
c=a;
a=b;
b=c;
}
2.
void swap (int a, int b)
{

a=a+b;

b=a-b;

a=a-b;

}
Solution2 is the best solution since no extra variable is required.

Share This Question

Challenge a friend or share with your study group.