Swap 2 Numbers Using Macros: C Program

preview_player
Показать описание

Today lets learn how to swap two integer numbers(using a temporary variable) using Macros in C.

Logic To Swap Two Numbers
First value of a is transferred to temp;
Next value of b is transferred to a.
Next value of temp is transferred to b.

C Programming Interview / Viva Q&A List

C Programming: Beginner To Advance To Expert
Рекомендации по теме
Комментарии
Автор

TechnoTip: You can avoid using the unnecessary/ugly 'temp' variable in your macro... just efficiently swap the numbers 'in-place' using a XOR mixer.
X^=Y; Y^=X; X^=Y; // Swaps X and Y

garychap