Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Thursday, February 24, 2011

Boolean

Here's a very simple program with standard questions :)

Question 1> : Is there anything wrong with this code ?
Question 2> : Will this code compile ?
Question 3> : Are there any specific options that I should give for compiling it ?
Question 4> : What is the output of this program ?



Tuesday, June 1, 2010

Find the value of the modified string

This is my favorite question. Its so much fun to listen to all the different answers and their logical explanations :)

Question

If my C program contains only the following 2 statements ( inside main function ofcourse !! ), then what is the value of the string pointed by "x", after the execution of these 2 statements.


Answer


Please follow this link to post your answer. I shall update this post with the correct answer in about a week's time.

Thursday, May 20, 2010

Delete any node in the middle of a linked list

Question

Given a pointer to a node in the middle of a linked list, how will you delete the present node ?

Answer
  
  The trick is in using simple pointer tricks. The "present node" should now point to the "next node". Make sure you delete the data in the "present node"

Friday, April 30, 2010

Reverse a string

Question

Write code to reverse a string in its place.

Answer

[ This basically means, that we cannot allocate extra memory for the reversed string and have to return it back in the same memory ]

To reverse a string in its place, we'll have to swap the 1st character with the nth character, then the 2nd character with the (n - 1)th character and so on ...


Corollary Question

Reverse the string in its place, without using a temporary variable.

Answer

The logic for this comes from the simple swapping technique that does not use a temporary variable.


Using the above logic we can re-write our function to reverse the string as below