Blogroll

Important Interview Questions with Answers C - 3

Saturday, 26 May 2012

1.What Will Be the output
   
main ()

   
{

      
int i, j, * ptr, * ptr1;

      
i = 10;

      
j = 10;

      
ptr = &i;

      
ptr1 = &j;



      
if (ptr == ptr1)

      
{

          
printf ("True");

      
}

     
else

     
{

          
printf ("False");

     
}

 
}

 
a. True b. False

 
c. Syntax error d. Run time Error
Answer: b
Explanation: In this program we are Contained Comparing the addresses by ptr & ptr1 not the value at ptr Those addresses and pointers ptr1 and Have the addresses of different variables so if Above is false.



 
2. How Many Times Will Get the loop below Executed?
main ()

 
{

          
int i;

         
for (i = 20, i = 10; i <= 20; i + +)

         
{

           
printf ("\ n% d", i);

         
}

  
}
a. 1 b. Run time Error
c. 11 d. Compilation Error
Answer: c
Explanation: i will start from 10.


3. How Many Times Will Get the loop below Executed?

  
main ()

  
{

           
int i, j;

          
i = 10;

          
for (j = i == 10 j <= 10, j + +)

          
{

            
printf ("\ n% d", j);

          
}

     
}
a. 1 b. 10
c. 11 d. Compilation Error
Answer: b
Explanation: An expression i == 10 return 1 and j get initialized to 1.


4. How Many Times Will Get the while loop Executed?

     
main ()

     
{

           
int a = 1;

           
while (a <= 100);

            
{

                  
printf ("% d", a + +);

              
}

       
}
a. 100 b. A
c. 0 d. Infinite
Answer: d
Explanation: Will execute infinite loop of No. Because of the times, at the end while loop.


5. How Many Times main () Will get called?
main ()
{

       
printf ("\ nMain Called again");

       
main ();
}
a. 1 b. 100
c. Hand Can not Be Called Recursively d. Infinite
Answer: d
Explanation: There is no requirement in the main () to stop the recursive calling of the main () hence it Will Be Called Infinite No. of times.



 
6. What Will Be the output of the Following program if the base address of array is 100.

  
main ()

  
{

       
gyan int [] = {1, 2, 3, 4, 5};

       
int i, * ptr;

       
ptr = gyan;

       
for (i = 0; i <4; i + +)

       
{

         
printf ("\ n% d", * ptr + +);

        
}

   
}
a. 1 2 3 4 b. 2 3 4 5
c. 100 101 102 103 d. 101 102 103 104
Answer: a
Explanation: ptr contains the base address of the array and printf () is printing the value at the current address Contained by ptr and then incrementing the pointer to point to the next array element address.



 
7. What Will Be the output of the Following program

 
main ()

  
{

      
gyan int [] = {10, 20, 30, 40, 50};

      
int i, * ptr;

      
ptr = gyan;

      
for (i = 0; i <4; i + +)

     
{

          
fun (ptr + +);

          
printf ("\ n% d", * ptr);

       
}

  
}

 
void fun (int * i)

  
{

      
* I * = i + 1;

  
}
a. 11 21 31 41 b. 20 30 40 50
c. 21 31 41 51 d. 10 20 30 40
Answer: b
Explanation: When We call the function fun () the current address Contained Will Get Passed by it and then it get incremented. For ex. If the base address of the array is 100 is then successively Elements are Stored at 102, 104, 106 and 108.
In the first call 100 to get Passed fun () and ptr Becomes 102. Now Called the function fun () manipulates the value at 100 and Stored in the main () function values ​​at the address Contained by ptr are getting printed.


8. What Will Be the output
main ()
{

     
char * ptr = "Gyantonic.com";

     
char a =

     
printf ("% c", * ptr + + + +);
}
a. Compilation Error b. H
c. G d. has
Answer: b
Explanation: * ptr + + + + Will retrieve the value by ptr Currently Pointed ie G and then increment the value and print Will H.

No comments:

Post a Comment

 

Most Reading

Tags

Sidebar One