ProgrammingHardGATE CS · Campus placements
uint8_t a = 0x3C, b = 0xA5; the statements a ^= b; b ^= a; a ^= b; run in that order. What are a and b afterwards?
- A. a = 0x3C, b = 0xA5
- B. a = 0x99, b = 0x99
- C. a = 0xA5, b = 0x3C
- D. a = 0x00, b = 0xFF
Correct answer: C. a = 0xA5, b = 0x3C
After the first step a holds 0x99 (the XOR of the two values). The second step restores b to 0x3C and the third restores a to 0xA5, so the values swap without a temporary.
More C Programming questions
- uint8t m = 0x0F; uint8t r = ~m; What is r?
- int a = -1; unsigned int b = 1u; What does if (a < b) evaluate to?
- int a = -7, b = 2; printf("%d %d", a / b, a % b); prints what?
- #define SQUARE(x) xx. What does printf("%d", SQUARE(2+3)) print?
- #define MAX(a,b) ((a)>(b)?(a):(b)). With int i = 7; int m = MAX(i++, 5); what are m and i afterwards?
- qsort is called on int arr[5] = {-7, 3, -2, 5, -4} with a comparator that returns (abs(a) > abs(b)) - (abs(a) < abs(b)) on the two…