ProgrammingVery hardGATE CS · Competitive coding (CP)
Assume int is 32 bits. What is printed?
Assume int is 32 bits. What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint8_t b = 0xF3;
int e = (int)(b ^ 0x80u) - 0x80;
printf("%d", e);
}- A. 243
- B. -13
- C. -141
- D. -12
Correct answer: B. -13
XOR with 0x80 flips the sign bit of the 8-bit field, leaving 0x73 = 115, and subtracting 0x80 gives -13. Skipping the subtraction gives 115, and the wrong constant gives -12.
More C Programming questions
- What is printed? c #include <stdint.h> #include <stdio.h> int tz(uint32t x) { int n = 0; while (!(x & 1u)) { x >>= 1; n++; } return n; }…
- Assume int is 32 bits with limits INTMIN = -2147483648 and INTMAX = 2147483647. What is printed? c #include <limits.h> #include <stdio.h>…
- int n = 8, c = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j = 2) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i = 3) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 100; i >= 1; i /= 2) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i++) for (int j = 1; j <= i; j++) c++; printf("%d", c); What is printed?