ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d", 5 % -3);
}- A. 2
- B. 1
- C. 4
- D. 3
Correct answer: A. 2
In C99 and later, the remainder takes the sign of the dividend, and 5 = (-3)(-1) + 2, so the result is 2.
More C Programming questions
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { printf("%d", strlen("hello") > 4 ? 1 : 0); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%d", (int)sizeof(char[3][4])); }
- What is printed? The hexadecimal literal is 0x1F and the comparison is with 31. c #include <stdio.h> int main(void) { printf("%d", 0x1F ==…
- What is printed? c #include <stdio.h> int main(void) { unsigned char c = 255; c += 1; printf("%d", c); }
- Assume int and unsigned int are 32-bit. What does this program print? #include <stdio.h> int main(void) { unsigned int a = 3; int b = -5…
- What does this program print? #include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int p = a + 1; int v = p++; int w = ++p…