Question 15Asked in DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1

What is the output of the code written in C? void main()

What is the output of the code written in C? void main() { printf("%d", 7%-3); printf("%d", -7%3); }
  1. A1 −1
  2. B−1 −1
  3. C−1 1
  4. D1 1
Show answerHide answer

Correct answer: (A) 1 −1

Explanation

In C the result of % takes the sign of the dividend: 7 % −3 = 1 and −7 % 3 = −1. The two printf calls print 1 and −1.

From DSSSB TGT Computer Science PYQ (Technical), 1 Aug 2021, Shift 1

This is question 15 of DSSSB TGT Computer Science PYQ (Technical), 1 Aug 2021, Shift 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.