Quick Test 7: if ... else ...

1. Which is not a valid comparison in C:

(a = b)
(a != b)
(a == b)
(a > b)

2. The proper syntax for simple branching is

if (condition) then
     instruction;
case condition
     instruction;
if (condition) 
     instruction;
case condition of
     instruction;


 
3. What is displayed when the following program is executed?

main()
{
  int a, b, c, d;

  a = 5; b = 3; c = 99; d = 5;
  if (a>6) printf("A");
  if (a>b) printf("B");
  if (b==c)
    {
      printf("C");
      printf("D");
    }
  if (b!=c) printf("E"); else printf("F");
  if (a>=c) printf("G"); else printf("H");
  if (a<=d)
    {
      printf("I");
      printf("J");
    }
}

4. What will be the output of the following program?

main()
{
  int a=1;

  if (a>0) 
    printf("The value of a ");
    printf("is larger than zero"); 
  else
    printf("The value of a ");
    printf("is less than zero"); 
}

The value of a is larger than zero
The value of a is less than zero
The structure of the program is wrong. We should group instructions with {..}
Depends on the value of a.