ProgrammingHardTCS NQT · Infosys
int a = -7, b = 2; printf("%d %d", a / b, a % b); prints what?
- A. -4 1
- B. -3 2
- C. -3 -1
- D. -2 -1
Correct answer: C. -3 -1
Since C99, integer division truncates toward zero, so -7 / 2 is -3 and the remainder takes the sign of the dividend: -7 = (-3)(2) + (-1).
More C Programming questions
- #define SQUARE(x) xx. What does printf("%d", SQUARE(2+3)) print?
- #define MAX(a,b) ((a)>(b)?(a):(b)). With int i = 7; int m = MAX(i++, 5); what are m and i afterwards?
- qsort is called on int arr[5] = {-7, 3, -2, 5, -4} with a comparator that returns (abs(a) > abs(b)) - (abs(a) < abs(b)) on the two…
- A qsort comparator is written as return (const int )a - (const int )b; Which statement is true?
- Which statement about the standard library function qsort is true?
- char names[] holds char pointers to strings and must be sorted alphabetically with qsort(names, n, sizeof names[0], cmp). Which comparator…