ProgrammingHardTCS NQT · Accenture

For uint32t a = 5 and b = 3, how many of these statements are true? (i) a - b > a (ii) (a - b) + b == a (iii) ~a == UINT32MAX (iv) a / b b == a Write the program's count of true statements.

For uint32_t a = 5 and b = 3, how many of these statements are true? (i) a - b > a (ii) (a - b) + b == a (iii) ~a == UINT32_MAX (iv) a / b * b == a Write the program's count of true statements.
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t a = 5, b = 3;
    int c = 0;
    if (a - b > a) c++;
    if ((a - b) + b == a) c++;
    if (~a == UINT32_MAX) c++;
    if (a / b * b == a) c++;
    printf("%d", c);
}
  1. A. 0
  2. B. 2
  3. C. 1
  4. D. 3

Correct answer: C. 1

Only statement (ii) holds: unsigned subtraction and addition cancel even when they wrap. Statement (i) is false because 2 is not greater than 5, and (iv) fails since 5 / 3 * 3 = 3.

More C Programming questions

Exams that ask this topic