ProgrammingVery hardProduct company OA
On a two's-complement machine with C99 division, what is printed?
On a two's-complement machine with C99 division, what is printed?
printf("%d %d", -13 % 8, -13 & 7);- A. -5 -5
- B. -13 3
- C. -5 3
- D. 3 3
Correct answer: C. -5 3
% truncates toward zero, so −13 % 8 = −5 (because −13 = −1·8 − 5). & 7 keeps the low three bits of the two's-complement pattern, which gives the non-negative remainder 3. The x & 7 trick for x % 8 is valid only for non-negative x.
More C Programming questions
- Assume IEEE-754 single-precision float and 32-bit unsigned int. What is printed? c union { float f; unsigned u; } v = {1.0f}…
- What is printed? c #line 100 int a = LINE; int b = LINE; printf("%d %d", a, b);
- What is printed? c #define CAT(a, b) a##b printf("%d", CAT(1, 2) + CAT(0x, 1F));
- What is printed? c #define f(x) ((x) 2) int (f)(int x) { return x + 100; } int main(void) { printf("%d %d", f(1), (f)(1)); }
- What is printed? c if (strcmp("abc", "abc")) puts("same"); else puts("different");
- Assume ASCII. What is printed? c int x = 'A' + 1.5; printf("%c %d", x, x);