GATE CS 2021 (Forenoon) — Question 47

Programming in CData Types, Syntax, Control Structures, LoopsMCQ2 marks · −2/3 if wrongMedium

Consider the following ANSI C program:
c
1#include <stdio.h>
2int main( )
3{
4    int i, j, count;
5    count = 0;
6    i = 0;
7    for (j = -3; j <= 3; j++)
8    {
9        if ((j >= 0) && (i++))
10            count = count + j;
11    }
12    count = count + i;
13    printf("%d", count);
14    return 0;
15}
16
Which one of the following options is correct?
  1. A
    The program will not compile successfully.
  2. B
    The program will compile successfully and output 10 when executed
  3. C
    The program will compile successfully and output 8 when executed.
  4. D
    The program will compile successfully and output 13 when executed.
Practise the full 2021-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkCompilers: Principles, Techniques & ToolsThe "Dragon Book" for parsing, syntax-directed translation and code generation.
Practise more on Data Types, Syntax, Control Structures, LoopsTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group