ProgrammingHardTCS NQT · Infosys · Product Company SDE
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int a = 61, b = 8; printf("%d %d %d %d", a / b, a % b, -a / b, -a % b); return 0; }
- A. 7 5 -7 5
- B. 7 5 -7 -5
- C. 7 5 -8 -5
- D. 7 5 -8 3
Correct answer: B. 7 5 -7 -5
C99 truncates integer division toward zero and % takes the sign of the dividend: 61/8=7, 61%8=5, −61/8=-7, −61%8=-5. (Python-style floor semantics gives different results.)
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h>…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…