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);
}- A. 0
- B. 2
- C. 1
- 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
- What is printed? c #include <stdio.h> int main(void) { int a[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) a[i][j] = i 4…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xABCD; printf("%u", (x >> 5) & 7u); }
- What is printed? c #include <ctype.h> #include <stdio.h> int main(void) { const char s = "Hello World"; int n = 0; for (const char p = s…
- What is printed? Assume int is 4 bytes and a pointer is 8 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof(int[10]) /…
- What is printed? Assume unsigned long long is 64 bits. c #include <stdio.h> int main(void) { printf("%llu", (1ULL << 63) 2); }
- How many positions differ between the two strings? Compute with this program. c #include <stdio.h> int main(void) { const char p =…