ProgrammingVery hardProduct company OA
What is printed?
What is printed?
size_t a = 3, b = 5;
if (a - b > 0) puts("bigger");
else puts("smaller");- A. Compilation error
- B. Undefined behaviour
- C. bigger
- D. smaller
Correct answer: C. bigger
size_t is unsigned, so 3 − 5 wraps to a huge positive value (SIZE_MAX − 1), which is greater than 0. Unsigned wrap-around is well defined. To compare sizes, write a > b instead of subtracting.
More C Programming questions
- What is printed? c int g(int a, int b) { return a == b ? a : a > b ? g(a - b, b) : g(a, b - a); } int main(void) { printf("%d", g(48…
- How many bytes does this code leak? c for (int i = 0; i < 3; i++) { char p = malloc(10); if (i == 1) free(p); }
- Assume 4-byte float and 8-byte double. What is printed? c #define PI 3.14 printf("%zu %zu", sizeof(PI), sizeof(PI 2.0f));
- What is printed? c int f(int n) { static int calls; if (n == 0) { int c = calls; calls = 0; return c; } calls++; return f(n - 1); } int…
- What is printed? c enum Op { ADD, SUB, MUL }; int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int…
- How many palindromic substrings does this code count? c const char s = "abba"; int n = 4, c = 0; for (int i = 0; i < n; i++) for (int j =…