• ( 1 ) Consider the following program fragment:
      for(c=1, sum=0; c <= 10; c++)
      {
      scanf("%d", &x);
      if( x < 0 ) continue;
      sum += x;
      }
      What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5

    • 1) 15
    • 2) 30
    • 3) 10
    • 4) 1
    • Discussion in forum
      Answer : 1) 15
      Solution :








      discussion


      Answer : 1) 15

    • ( 3 ) What is the output of this C code?
      int main()
      {
      if (printf("%d", printf(")))
      printf("We are Happy");
      else if (printf("1"))
      printf("We are Sad");
      }

    • 1) 0We are Happy
    • 2) 1We are Happy
    • 3) 1We are Sad
    • 4) Compile time error
    • Discussion in forum
      Answer : 4) Compile time error
      Solution :








      discussion


      Answer : 4) Compile time error

    • ( 4 ) What is the output of this C code?
      int main()
      {
      int i = 0, j = 0;
      l1: while (i < 2)
      {
      i++;
      while (j < 3)
      {
      printf("booK\n");
      goto l1;
      }
      }
      }

    • 1) book book
    • 2) Compile time error
    • 3) book book book book
    • 4) Infinite loop
    • Discussion in forum
      Answer : 1) book book
      Solution :








      discussion


      Answer : 1) book book

    • ( 5 ) What's wrong in the following statement, provided k is a variable of type int?
      for(k = 2, k <=12, k++)

    • 1) The increment should always be ++k .
    • 2) The commas should be semicolons
    • 3) There should be a semicolon at the end of the statement.
    • 4) The variable k can't be initialized.
    • Discussion in forum
      Answer : 2) The commas should be semicolons
      Solution :








      discussion


      Answer : 2) The commas should be semicolons

    • ( 6 ) Comment on the output of this C code?
      switch (ch)
      {
      case 'a':
      case 'A':
      printf("true");
      }

    • 1) if (ch == 'a' && ch == 'A') printf("true");
    • 2) if (ch == 'a') if (ch == 'a') printf("true");
    • 3) if (ch == 'a' || ch == 'A') printf("true");
    • 4) Both 1 & 2
    • Discussion in forum
      Answer : 3) if (ch == 'a' || ch == 'A') printf("true");
      Solution :








      discussion


      Answer : 3) if (ch == 'a' || ch == 'A') printf("true");

    • ( 7 ) What is the output of this C code?
      int main()
      {
      int x = 1;
      if (x > 0)
      printf("inside if\n");
      else if (x > 0)
      printf("inside elseif\n");
      }

    • 1) inside if
    • 2) inside elseif
    • 3) inside if inside elseif
    • 4) Compile time error
    • Discussion in forum
      Answer : 1) inside if
      Solution :








      discussion


      Answer : 1) inside if

    • ( 9 ) What is the right choice, if the following loop is implemented?
      void main()
      {
      int num = 0;
      do{
      --num;
      printf("%d", num);
      }while( ++num >= 0 );
      }

    • 1) A run time error will be generated.
    • 2) The program will not enter into the loop.
    • 3) There will be a compilation error reported.
    • 4) The loop will run infinitely many times.
    • Discussion in forum
      Answer : 4) The loop will run infinitely many times.
      Solution :








      discussion


      Answer : 4) The loop will run infinitely many times.

    • ( 10 ) What is the output of this C code?
      int main()
      {
      int i = 0;
      while (i = 0)
      printf("True\n");
      printf("False\n");
      }

    • 1) True (infinite time)
    • 2) True (1 time) False
    • 3) FALSE
    • 4) Compiler dependent
    • Discussion in forum
      Answer : 3) FALSE
      Solution :








      discussion


      Answer : 3) FALSE





Top