C& CPP Tutorials
About C
Program Structure
Running C Program
Variables, constants
Operators
Control Structure
Array
Function
Pointers
Preprocessor
Structure
File
Bitwise Operators
Recursion
 Data Structures
Introduction
Stacks
Queues
Linked List
Sorting 
Searching
 Test Your Skill
Fundamentals
Input and Output
Branching and Looping
Function
Pointers I
Pointers II
Structure and Union
Sample Problems I
Sample Problems II
 Help and Support
C Forum
Source code
C  Yahoo Group
C Compilers
 

Decision-making, Bit-wise operations,  Branching and Looping 

[Q001] What will be the output of the following program :
 
int main()
 {
   printf("Hi!");
   if (-1)
      printf("Bye");
   return(0);
 }

  (a)No Output
  (b)Hi!
  (c)Bye
  (d)Hi!Bye

 [Q002] What will be the output of the following program :
 int main()
 {
   printf("Hi!");
   if (0 || -1)
      printf("Bye");
   return(0);
 }

  (a)No Output
 (b)Hi!
 (c)Bye

 
(d)Hi!Bye

 [Q003] What will be the output of the following program :

int main()
 {
   printf("Hi!");
   if (!1)
      printf("Bye");
   return(0);
 }

 (a)Compile-Time error
 (b)Hi!
 (c)Bye
 (d)Hi!Bye

 [Q004] What will be the output of the following program :
 
int main()
 {
   printf("Hi!");
   if !(0)
      printf("Bye");
   return(0);
 }

 (a)Compile-Time error
 (b)Hi!
 (c)Bye
 (d)Hi!Bye

[Q005] What will be the output of the following program :

 int main()
 {
   printf("Hi!");
   if (-1+1+1+1-1-1-1+(-1)-(-1))
      printf("Bye");
   return(0);
 }

 (a)No Output
 (b)Hi!
 (c)Bye
 (d)Hi!Bye

  [Q006] What will be the output of the following program :
 
 int main()
 {
   if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int))
      printf("Testing");
   printf("OK");
   return(0);
 }

 (a)No Output
 (b)OK
 (c)Testing
 (d)TestingOK

[Q007] What will be the output of the following program :

 int main()
 {
   int a=1,b=2,c=3,d=4,e;
   if (e=(a & b | c ^ d))
      printf("%d",e);
   return(0);
 }

  (a)0
 (b)7
 (c)3
 (d)No Output

[Q008] What will be the output of the following program :
int main()
 {
   unsigned val=0xffff;
   if (~val)
      printf("%d",val);
   printf("%d",~val);
   return(0);
 }

 (a)Compile-Time error
 (b)-1
 (c)0
 (d)-1 0

[Q009] What will be the output of the following program :

 
 int main()
 {
   unsigned a=0xe75f,b=0x0EF4,c;
   c=(a|b);
   if ((c > a) && (c > b))
      printf("%x",c);
   return(0);
 }

 (a)No Output
 (b)0xe75f
 (c)0xefff
 (d)None of these

 [Q010] What will be the output of the following program :
 
  
 
 int main()
 {
   unsigned val=0xabcd;
   if (val>>16 | val<<16)
   {
      printf("Success");
      return;
   }
   printf("Failure");
   return(0);
 }

  (a)No Output
 (b)Success
 (c)Failure
 (d)SuccessFailure

[Q011] What will be the output of the following program :

 
 int main()
 {
   unsigned x=0xf880,y=5,z;
   z=x<<y;
   printf("%#x %#x",z,x>>y-1);
   return(0);
 }

 (a)1000 f87
 (b)8800 0xf88
 (c)1000 f88
 (d)0x1000 0xf88

 [Q012] What will be the output of the following program :
   
int main()
 {
   register int a=5;
   int *b=&a;
   printf("%d %d",a,*b);
   return(0);
 }

 (a)Compile-Time error
 (b)Run-Time error
 (c)5 5
 (d)Unpredictable

[Q013] What will be the output of the following program :
auto int a=5;
 int main()
 {
   printf("%d",a);
   return(0);
 }

 (a)Compile-Time error
 (b)Run-Time error
 (c)5
 (d)Unpredictable

[Q014] What will be the output of the following program :
 int main()
 {
   auto int a=5;
   printf("%d",a);
   return(0);
 }

 (a)Compile-Time error
 (b)Run-Time error
 (c)5
 (d)Unpredictable

[Q015] What will be the output of the following program :

 
int main()
 {
   int a=1,b=2,c=3,d=4;
   if (d > c)
      if (c > b)
         printf("%d %d",d,c);
      else if (c > a)
         printf("%d %d",c,d);
   if (c > a)
      if (b < a)
         printf("%d %d",c,a);
      else if (b < c)
         printf("%d %d",b,c);
   return(0);
 }

 (a)4 3 3 4
 (b)4 3 3 2
 (c)4 32 3
 (d)4 33 1

 [Q016] What will be the output of the following program :
 int main()
 {
   int a=1,b=2,c=3,d=4;
   if (d > c)
      if (c > b)
         printf("%d %d",d,c);
      if (c > a)
         printf("%d %d",c,d);
   if (c > a)
      if (b < a)
         printf("%d %d",c,a);
      if (b < c)
         printf("%d %d",b,c);
   return(0);
 }

 (a)4 32 3
 (b)4 33 42 3
 (c)4 3 3 4 2 3
 (d)None of these

 [Q017] What will be the output of the following program :
 int main()
 {
   int a=1;
   if (a == 2);
      printf("C Program");
   return(0);
 }

  (a)No Output
 (b)C Program
 (c)Compile-Time Error

[Q018] What will be the output of the following program :
 
 
int main()
 {
   int a=1;
   if (a)
      printf("Test");
   else;
      printf("Again");
   return(0);
 }

 (a)Again
 (b)Test
 (c)Compile-Time Error
 (d)TestAgain

 [Q019] What will be the output of the following program :
 int main()
 {
   int i=1;
   for (; i<4; i++);
        printf("%d\n",i);
   return(0);
 }

  (a)No Output
  (b)1
      2
      3
  (c)4
  (d)None of these

 [Q020] What will be the output of the following program :
 
 
 int main()
 {
   int a,b;
   for (a=0; a<10; a++);
        for (b=25; b>9; b-=3);
             printf("%d %d",a,b);
   return(0);
 }

  (a)Compile-Time error
 (b)10 9
 (c)10 7
 (d)None of these

[Q021] What will be the output of the following program :
int main()
 {
   float i;
   for (i=0.1; i<0.4; i+=0.1)
        printf("%.1f",i);
   return(0);
 }

 (a)0.10.20.3
 (b)Compile-Time Error
 (c)Run-Time Error
 (d)No Output

[Q022] What will be the output of the following program :

int main()
 {
   int i;
   for (i=-10; !i; i++);
        printf("%d",-i);
   return(0);
 }

 (a)0
 (b)Compile-Time Error
 (c)10
 (d)No Output

 [Q023] What will be the output of the following program :

 
int main()
 {
   int i=5;
   do;
      printf("%d",i--);
   while (i>0);
   return(0);
 }

 (a)5
 (b)54321
 (c)Compile-Time Error
 (d)None of these

[Q024] What will be the output of the following program :

int main()
 {
   int i;
   for (i=2,i+=2; i<=9; i+=2)
        printf("%d",i);
   return(0);
 }

 (a)Compile-Time error
 (b)2468
 (c)468
 (d)None of these

[Q025] What will be the output of the following program :

 
int main()
 {
   int i=3;
   for (i--; i<7; i=7)
        printf("%d",i++);
   return(0);
 }

 (a)No Output
 (b)3456
 (c)23456
 (d)None of these

[Q026] What will be the output of the following program :

int main()
 {
   int i;
   for (i=5; --i;)
        printf("%d",i);
   return(0);
 }

 (a)No Output
 (b)54321
 (c)4321
 (d)None of these

 
[Q027] What will be the output of the following program :
 int main()
 {
   int choice=3;
   switch(choice)
   {
     default:
         printf("Default");

     case 1:
         printf("Choice1");
         break;

     case 2:
         printf("Choice2");
         break;
   }
   return(0);
 }

 (a)No Output
 (b)Default
 (c)DefaultChoice1
 (d)None of these

 [Q028] What will be the output of the following program :

 
int main()
 {
   static int choice;
   switch(--choice,choice-1,choice-1,choice+=2)
   {
       case 1:
           printf("Choice1");
           break;

       case 2:
           printf("Choice2");
           break;

       default:
           printf("Default");
   }
   return(
0);
 }

 (a)Choice1
 (b)Choice2
 (c)Default
 (d)None of these

[Q029] What will be the output of the following program :

 
int main()
 {
   for (;printf(""););
   return(0);
 }

 (a)Compile-Time error
 (b)Executes ONLY once
 (c)Executes INFINITELY
 (d)None of these

  [Q030] What will be the output of the following program :
 
int main()
 {
   int i;
   for (;(i=4)?(i-4):i++;)
        printf("%d",i);
   return(0);
 }

 (a)Compile-Time error
 (b)4
 (c)Infinite Loop
 (d)No Output

Solutions for the above queries.

Back Next
 

Google