"For every success of a man there will be a countless pain in his heart and that pain makes him a successful person in life"

When You are at the Peak of Concentration, You don't feel whether u r programming in C/C#/JAVA or any other, You just type the keys on keyboard and your sub-conscious mind does the rest...!

Myspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace Glitters




 
   

C - Iterations, Operators

   
 


 

 

Home

Guestbook

GALLERY

MySQL

C/C++ Interview Questions

C/C++ Test Paper 1

C/C++ Test Paper 2

C Tricky Snippets

C - Pointers

C - Functions

C - Iterations, Operators

Java Interview Questions

Java Fundamentals

Java FAQs

J2EE - FAQs

Java - Best Collection Ever

Java/J2EE Test 1

Java Test 2

Java Servlets - FAQs

SCJP 5.0 Syllabus

SCJP Exam 1

SCJP Exam 2

SCJP Exam 3

SCJP Exam 4

SCJP Exam 5

Relational Database Management Systems(RDBMS) Imp. Concepts

SQL Server - Interview Questions

SQL Server 2

Data Structures

OOPS - FAQs

Object Oriented Programming (OOP) Concepts

Operating Systems - FAQs

Operating System Concepts

Networking Concepts

UML - Quick Reference

VB - FAQs

Secrets About Windows Operating Systems

 


     
 

 

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("%dn",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
 

Solutions - Decision-making, Bit-wise operations,  Branching and Looping
[Q001] 
 (b)Compile-Time Error
Too few arguments to function 'printf'.
 
 [Q002] 
(c)No Output
Here NULL is treated as a NULL string.
 
[Q003] 
 (c)%
% is a format specifier and it prints %. The excess arguments are merely ignored i.e. 7.
 
[Q004]
 (d)//
is an escape sequence but not /. Thus it prints // and the excess arguments are merely ignored i.e. 5.
 
[Q005] 
(c)d%
%d is a format specifier but not d%. Thus it prints d% and it ignores the excess arguments i.e. 8.
 
[Q006] 
 (a)123
"%d"+0 in the printf statement has no effect on the output operation. Thus it prints 123.
 
[Q007] 
 (c)d

"%d"+1 (or > 0) in the printf statement affects the program output by considering "%d" as string and ignores the excess argument i.e. 123. Here 1 refers to the index i.e. 2nd character in the array or string "%d"
 
[Q008] 
 (b)Hi!Bye6

L->R priority and the length of the strings 'Hi!' & 'Bye' is 3+3=6. The statement printf returns the no. of bytes displayed onto the screen.
 
[Q009] 
 (b)Hi!Bye9
L->R priority and the length of the strings 'Hi!' & 'Bye' is 3*3=9. The statement printf returns the no. of bytes displayed onto the screen.
 
[Q010] 
(a)0

L->R priority and the length of the two strings are 0+0=0. The statement printf returns the no. of bytes displayed onto the screen.
 
[Q011]
 (b)Friends

(base adress of the string 'Hi Friends')+0 points to the value 'H'. Now the NEW (base address) equals (base address)+3 that points to the character 'F'. Thus it prints the string from 'F' onwards.
 
[Q012] 
(b)C For Swimmers
The value returned by the printf statements need not be stored or simply ignored. It is a valid C code.
 
[Q013] 
  (c)/*-*/
is an escape sequence character. Be careful while analyzing such statements.
 
[Q014]
  (d)7
It is a VALID C code. Prints 7 and returns the same to the Operating System. NOTE: Last printf statement will not be executed.
 
[Q015] 
 (c)Infinite Loop

main is a function so it can be called by any other function including itself. Here main is called by itself and it runs infinite number of times i.e. till the memory exists.
 
[Q016] 
  (d)WorkHard
It is a valid C code. First it prints the word 'Work' and then 'Hard'.
 
 [Q017] 
(c)25

First parameter contains the format specifier & the Second parameter contains the actual value 25.
 
[Q018] 
 (a)Compile-Time Error

Generates compile-time error message.
Parse error before '.' token.
 
 [Q019] 
(a)10
R->L priority. The second format specifier '%d' is an excess argument and it is ignored.
 
[Q020]
 (b)Compiler dependant

The output varies from compiler to compiler in different platforms.
 
[Q021] 
 Execute & understand the output format.
 
 [Q022] 
 (b)2

It is a valid C code. scanf statement is embedded inside the printf statement get executed first. scanf statement returns the number of input fields successfully scanned, converted and stored.
 
[Q023] 
  (b)30

During pre-processing the macro calls are merely replaced by the replacement text. Be careful while analyzing macro calls.
 
[Q024] 
(c)Compile-Time Error

Unterminated comment or Comment statement not ended properly i.e */ is missing in the above C code.
 
[Q025] 
  (d)a
Alphabet 'a' is the ASCII equivalent of 97. printf statement return the number of bytes displayed onto the screen and it can be ignored.
 
[Q026] 
  (d)CSkills7

printf statement return the number of bytes displayed onto the screen. The length of the strings 'C' and 'Skills' are 1 + 6 = 7.
 
[Q027]
(b)TestSuccess

It is valid C code. printf statement return the number of bytes displayed onto the screen.
 
 [Q028] 
 
(a)bbbbb5 (where b means blankspace)

Here '*' specifies the precision. First val is the precision and second val is the actual value. Thus it prints 5 BLANK SPACES & then the value 5.
 
 [Q029] 
 (c)55

%d format specifier is replaced by the contents of the variable val i.e. 5 followed by another 5.
 
[Q030]
(a) Compile-Time Error

Incorrect usage of pair of braces } and {.  Correct usage : Each compound statement should be enclosed within a pair of braces, i.e. { and

 
 

 

 

Thank You.. Visit Again

This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free