Sunday, 19 May 2013

Coin Machine Weighing Puzzle


As per the puzzle you have 20 coin machines, each of which produce the same kind of coin. you know how much a coin is supposed to weigh. one of the machines is defective, in that every coin it produces weighs 1 ounce less than it is supposed to. you also have an electronic weighing machine. how can you determine which of the 20 machines is defective with only one weighing? (by one use, we mean you put a bunch of stuff on the machine and read a number, and that's it -- you not allowed to accumulate weight onto the machine and watch the numbers ascend, because that's just like multiple weighings). you are allowed to crank out as many coins from each machine as you like.

Find the defective box

You have 10 boxes of balls (each ball weighing exactly 10 gm) with one box with defective balls (each one of the defective balls weigh 9 gm). You are given an electronic weighing machine and only one chance at it. How will find out which box has the defective balls?

7 days work remuneration


This puzzle is also asked by Microsoft. But this is famous puzzle asked by almost all companies nowadays interviews while recruiting people. This puzzle is not math oriented. By using simple analytic logic we can answer this puzzle.

Puzzle : 

Lets us consider someone working for you seven days. You have a Gold bar to pay him. You must pay the worker for their work at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker? (Assuming equal amount of work is done during each day thus requiring equal amount of pay for each day).

Saturday, 18 May 2013

Love is great

A woman came out of her house and saw 3 old men with long white
beardssitting in her front yard. She did not recognize them. She said
"I don't think I know you, but you must be hungry. Please come in and have
something to eat. "Is the man of the house home?", they asked.
"No", she said. "He's out."
"Then we cannot come in", they replied.
In the evening when her husband came home, she told him what had
happened.
"Go tell them I am home and invite them in!"
The woman went out and invited the men in. "We do not go into a
House together," they replied.
"Why is that?" she wanted to know.
One of the old men explained: "His name is Wealth," he said
pointing to one of his friends, and said pointing to another one, "He is Success,
and I am Love."
Then he added, "Now go in and discuss with your husband which one
of us you want in your home."
The woman went in and told her husband what was said. Her husband was overjoyed.
"How nice!!", he said.
"Since that is the case, let us invite Wealth. Let him come and fill our home with wealth!"
His wife disagreed. "My dear, why don't we invite Success?"
Their daughter-in-law was listening from the other corner of the house.
She jumped in with her own suggestion: "Would it not be better to invite Love?
Our home will then be filled with love!"
"Let us heed our daughter-in-law's advice," said the husband to his wife.
"Go out and invite Love to be our guest."
The woman went out and asked the 3 old men,
"Which one of you is Love? Please come in and be our guest."
Love got up and started walking toward the house. The other 2 also got up and followed him.
Surprised, the lady asked Wealth and Success:
"I only invited Love, Why are you coming in?"
The old men replied together: "If you had invited Wealth or Success, the other two of us
would've stayed out, but since you invited Love, wherever He goes, we go with him.
Wherever there is Love, there is also Wealth and Success!!!!!!"

Are girls wiser than boys ???

One day, a girl, 16yrs old, heard from her mother that if she does a regular prayer for 4 yrs, a divine "Angel" would come to her in her dreams & give her 3 boons (Vardaan). So she decided to do it. She completed 4 yrs successfully, doing prayer regularly.

Now it was a day for "Angel" to come. So she slept earlier with thoughts in her mind to ask. And, really an "Angel" comes in her dreams. Now this is the dialogue between them.

Angel: O Girl, you prayed to me regularly within last 4 yrs, so I am very very happy with you. I will complete any of your 3 wishes. You can ask anything you like, but there is one condition.

Girl: Condition!, what is that?

Angel: You have a boy-friend?

Girl: Yes.

Angel: When you were doing a prayer, he was waiting for you, so he also sacrificed same as you. Moreover, he didn't know anything about boon and all, so he is also eligible for the boons. So whatever you will ask, he will get 10 times more than that of you. If you are agreed, then proceed for the 1 st boon.

Girl: (After thinking for some time ...): Yes, I am ready.

Girl: 1st, make me 10 times richer than the richest person in the world.

Angel: But your boy-friend will be 10 times richer than you.

Girl: It's OK.

Angel: Be as you wish!

Girl: 2nd, Make me 10 times more beautiful than the most beautiful girl
in the world. Angel: But your boy-friend will be 10 times handsome than the
most handsome boy in the world.

Girl: It's OK.

Angel: Be as you wish.

Angel: Now the last boon remains.

Girl: O Angel, please give me a MILD HEART-ATTACK.

Angel: What? Are you sure!

Girl: Yes. Very sure!

Angel: Be as you wish.

Think friends,

what happened to her boy-friend, he got a severe heart-attack & died at once, while the girl remained alive. Thus, the girl became the world's most beautiful girl and the richest one, too.

Moral of the story: So intelligent the girls are! Girls are really more intelligent than we believe about them to be. So be careful boys!

Now, girls please stop reading ... boys continue till the end of the post

******

******
******

******
******

******
******

******
******

******
******

******

******

******

******

******

******

******

******

******

******

******

Dear boys, don't worry, actually what happened is something different than what you all think! Actually,the girl's boy-friend got a heart-attack, 10 TIMES MILDER than that of the girl. So the boy-friend lived longer than the girl, being world's richest and the most handsome boy.

Moral of the story: Dear boys, the girls are not really that much intelligent than what we believe them to be. So don't worry if you think that you have girl-friend,intelligent than you.

Hey....I told u girls not to read......

Mother is Great !!!

A little boy came up to his mother in the kitchen one evening while she
was fixing supper, and he handed her a piece of paper that he had been
writing on.
After his mom dried her hands on an apron she read it,
and this is what it said:

For cutting the grass : $5.00
For cleaning up my room this week: $1.00
For going to the store for you : $0.50
Babysitting my kid brother while you went shopping : $0.25
Taking out the garbage : $1.00
For getting a good report card : $5.00
For cleaning up and raking the yard : $2.00
Total owed :$14.75

Well, his mother looked at him standing there, the boy could see the
memories flashing through her mind.

She picked up the pen, turned over the paper he'd written on,
and this is what she wrote:

For the nine months I carried you while you were growing inside me :
No Charge.
For all the nights that I've sat up with you, doctored and prayed for you:
No Charge.
For all the trying times, and all the tears that you've caused through the
years :
No Charge.
For all the nights that were filled with dread,and for the worries I knew
were ahead :
No Charge.
For the toys, food, clothes, and even wiping your nose : No Charge.
Son, When you add it up, the cost of my love is : No Charge


When the boy finished reading what his mother had written,
there were big tears in his eyes,
and he looked straight at his mother and said,
"Mom, I sure do love you".

And then he took the pen and in great big letters he wrote:
"PAID IN FULL"

A very good love letter and a better reply to it

A teenage college guy sent a love letter (in Q/A
format) to his classmate.

My Dearest Reshma,

Please answer the following questionnaire. For Options (a)10 marks,
(b) 5marks and
(c) 3 marks.

1) Whenever you enter the class room, your sight always falls on me
because:
(a) of love
(b) you couldn't control seeing me
(c) really ... am I doing it?

2) Whenever professor cracks joke, you laugh and turn and look at me
because:
(a) you always like to see me smiling
(b) you are testing whether I like jokes
(c) you are attracted by my smile

3) When you were singing in the class, I entered and immediately you
stopped singing because:
(a) you are so coy to sing before me
(b) my presence influenced you
(c) you feared that whether I'll like your song

4) When you were showing your childhood photo, when I asked for it, you
hide it because:
(a) you felt ashamed
(b) you felt uneasy
(c) you don't know

5) During trekking, myself and my friend gave you hand for lifting you
and you took only my friend's
because:
(a) you enjoyed my disappointment
(b) you won't feel leaving my hand after grabbing
(c) you don't know

6) You were waiting yesterday for bus and didn't get into your bus...
(a) you were waiting for me
(b) you were dreaming about me and didn't notice the bus
(c) that bus was crowded

7) You introduced me to your parents when they came to college because:
(a) I am going to be your groom
(b) you just want to know what your parents think about me
(c) just you felt like introducing me to them

8) I told that I like girls wearing roses. Next day, you came with a
rose on your head because:
(a) to fulfill my wish
(b) you like roses
(c) by chance you got a rose

9) On that day, it was my birthday. you too came to temple early at 6:00
A.M because:
(a) you want to pray along with me
(b) you want to meet me before any one could meet on my birthday
(c) you want to wish me at temple because you are spiritual.

If you have scored more than 40, then you are loving me. Don't delay in
expressing it. If you have scored between 30 and 40, love is budding in
your heart and it's getting ready to bloom. If you have scored less than
30, you are in confusion whether to love me or not. Eagerly awaiting
your reply.. Love, Aakash



Reshma's reply letter was also in Q/A format........
Aakash,
Please answer the following Yes/No questionnaire.
1) If somebody sits in the first row, normally people entering the
class, sees them.
(a) Yes
(b) No

2) If a girls laughs and looks anyone, is it love?
(a) Yes
(b) No

3) While singing, if somebody forgets lines of the songs, will he/she
stop singing or not?
(a) Yes
(b) No

4) I was showing to my friends (who are all girls) my childhood photo.
You poked your nose inside..... right ?
(a) Yes
(b) No

5) I avoided to hold your hand during trekking. Couldn't you understand
yet?
(a) Yes
(b) No

6) Should I not wait for my best friend (Anjali) at the bus stand?
(a)Yes
(b) No

7) Shouldn't I introduce you to my parents as a friend?
(a) Yes
(b) No

8) You have said you also like Lotus, cauliflower, banana's flower. Is
it true ?
(a) Yes
(b) No

9) Oh was that your birthday. That's why I could see you in temple. I
come daily to Temple. Do you know ?
(a) Yes
(b) No

If you have answered "Yes" to any of the question, then I am not loving
you. If you have answered "No", then you don't know the meaning of Love.
Hope everything is clear to you. Reshma

Technical Interview at TCS

Below is my technical interview at TCS where I was the first one to get selected among 55 students chosen from our college.

H: interviewer
I:myself


H: Ok tell me about urself ?
I: Besides all the information given in my curriculum vitae , I am consistent as u can see from academics marks . I can converse well with people . I can work better in a team . The fundamental principle of my life is that “Successful peop;e have the ability to read between the lines” . I like to do things in an innovative way .
H(interrupting me): Ok , tell me the last thing u have done innovatively , anything even outside academics ?
I:Sir , one day one of my friends texted me a msg “ Hay , Have u done my work ?” and after so much of scrolling down it was written “99% of the people will call u on reading the first line .Fortunately u r not among them .”
Now what common people will do ? They will just look at the msh , laugh and keep the mobile in the pocket . But I did something different.
I texted her “Ur work is over but there is some problem .” After so much of scrolling I wrote the same thing as was written by her i.e “99% of the ….” . !!!!!!!!!!!
H:In what u r expert subjects(OS and CN) or languages ?
I: Sir , languages and especially JAVA .
H:Ok Tell me what is polymorphism ?
I: It is the use of same thing for different purposes . There r two types of it . 1- Compile time (method overloading) 2-Run time (method over riding ).
H: Can u give me any real world example of polymorphism ?
I: Sir If in a class we have one add method taking two integer arguments , we can overload this add method which takes two float values .
H(interrupting me ): No No , I want real world eg . outside java
I: sorry sir , I don’t know .
H: Which books u referred ?
I: Complete Reference and Head First
H: It is given in Complete Ref
I:Sorry Sir , I don’t remember.
H:Write a code snippet describing use of Inheritance and Polymorphism ?
I:
Class A{
int add(int a,int b)
{
Return (a+b);
}
// overloading
Float add(float a, float b)
{
Return(a+b);
}
}
Class B extends A{
// over riding
int add(int a, int b){
return(a++ + b ++);
}
} // class B ends
H: U gave seminar on JDBC . Tell me how u represented .
I: Sir , first I explained why there was need for JDBC . Before JDBC , ODBC( open database connectivity ) by Microsoft was used . But ODBC drivers were written in platform dependent lang. like C, C++ etc . Also ODBC drivers need to be installed on the client . JDBC drivers(type 3 and type 4) are in java so platform independent .
H(interrupting me):ok ok , tell me how will u establish connection with DBMS in JDBC ?
I:DriverManager class has getConnection(String url ) method. When we call this method with proper url , it returns an Object of type Connection(an interface).
General format of url is :
Jdbc:subprotocol:subname
For eg: jdbc:odbc:www.hostname:port no/DSN
H: How can we find the hostname ?
I: Sir , We can find it using InetAddress class of java.net package .
H: Ya , that’s one solution . But I want non Java solution .
I: Sorry Sir , I don’t know .
H: What is Java bean ?
I:Java Bean is a java class following some conventional rules and which can be reused . We can create reusable components using java Beans .
H: Give me difference between Java class and java bean
I: Java Beans will hava getters and setters method for each property (fields).
H: Explain me how ?
I:
General Format :
Public T getN();
Public void setN(T);
Where T- Type
N-Name of property
H: If I tell u to work in PHP will u be able to do ?
I: Yes , sure
H: How much time will u take ?
I: One month
H(was surprised): One Month !!!!
I: OK,20 days
He smiled.
H: Ur interest is Android Mobile Application Development . From where u obtained the resources ?
I: code.google.com , android.developers.com , and wrox publication book on Android
H:ok , u can leave
I: Ok , It was pleasure meeting u .
H: me too .
I: Sir , I attended ur seminar on Cloud Computing which u gave two months back in our college .It was very interesting .
H: I was abt to ask that . But forgot . Ok Now I don’t want to ask . U can go.

Some Tough OCJP Questions


  2.   Given:
 1. public class BackHanded {
 2.   int state = 0;
 3.   BackHanded(int s) { state = s; }
 4.   public static void main(String... hi) {
 5.     BackHanded b1 = new BackHanded(1);
 6.     BackHanded b2 = new BackHanded(2);
 7.     System.out.println(b1.go(b1) + " " + b2.go(b2));
 8.   }
 9.   int go(BackHanded b) {
10.     if(this.state == 2) {
11.       b.state = 5;
12.       go(this);
13.     }
14.     return ++this.state;
15. } }
    What is the result?
  A.  1 2
  B.  1 3
  C.  1 6
  D.  1 7
  E.  2 6
F.  2 7
G.  Compilation fails.
H.  An exception is thrown at runtime.


4.   Given:
 3. class Sport {
 4.   Sport play() { System.out.print("play "); return new Sport(); }
 5.   Sport play(int x) { System.out.print("play x "); return new Sport(); }
 6. }
 7. class Baseball extends Sport {
 8.   Baseball play() { System.out.print("baseball "); return new Baseball(); }
 9.   Sport play(int x) { System.out.print("sport "); return new Sport(); }
10.
11.   public static void main(String[] args) {
12.     new Baseball().play();
13.     new Baseball().play(7);
14.     super.play(7);
15.     new Sport().play();
16.     Sport s = new Baseball();
17.     s.play();    
18. } }
   What is the result?
A.  baseball sport sport play play
B.  baseball sport play x play sport
C.  baseball sport play x play baseball
D.  Compilation fails due to a single error.
E.  Compilation fails due to errors on more than one line.

Given:
 2. class Paratrooper implements Runnable {
 3.   public void run() {  
 4.     System.out.print(Thread.currentThread().getName() + " ");
 5. } }
 6. public class Jump {
 7.   static Paratrooper p;
 8.   static { p = new Paratrooper(); }
 9.   { Thread t1 = new Thread(p, "bob"); t1.start(); }
10.   public static void main(String[] args) {
11.     new Jump();
12.     new Thread(new Runnable() { public void run() 
          { ; }}, "carol").start();
13.     new Thread(new Paratrooper(), "alice").start();
14.   }
15.   Jump() { Thread t2 = new Thread(p, "ted"); t2.start(); }
16. }
Which are true? (Choose all that apply.)
A.  The output could be ted bob alice
B.  The output could be bob alice carol
C.  The output could be bob carol ted alice
D.  Compilation fails due to an error on line 8.
E.  Compilation fails due to an error on line 9.
F.  Compilation fails due to an error on line 12.
G.  Compilation fails due to an error on line 15.

4. Given:
 2. public class Volume {
 3.   Volume v;
 4.   int size;
 5.   public static void main(String[] args) {
 6.     Volume myV = new Volume();
7.     final Volume v2;
 8.     v2 = myV.doStuff(myV);
 9.     v2.v.size = 7; 
10.     System.out.print(v2.size);
11.   }
12.   Volume doStuff(Volume v3) {
13.     v3.size = 5;
14.     v3.v = new Volume();
15.     return v3;
16. } }
What is the result? (Choose all that apply.)
A.  5
B.  7
C.  Compilation fails due to an error on line 8.
D.  Compilation fails due to an error on line 9.
E.  Compilation fails due to an error on line 13.
F.  Compilation fails due to an error on line 14.

Given:
 1. public class Endless {
 2.   public static void main(String[] args) {
 3.     int i = 0;
 4.     short s = 0;
 5.     for(int j = 0, k = 0; j < 3; j++) ;
 6.     for(int j = 0; j < 3; counter(j)) ;
 7.     for(int j = 0, int k = 0; j < 3; j++) ;
 8.     for(; i < 5; counter(5), i++) ;
 9.     for(i = 0; i < 3; i++, System.out.print("howdy ")) ;
10.   }
11.   static int counter(int y) { return y + 1; }
12. }
What is the result? (Choose all that apply.)
A.  howdy howdy howdy
B.  The code runs in an endless loop.
C.  Compilation fails due to an error on line 5.
D.  Compilation fails due to an error on line 6.
E.  Compilation fails due to an error on line 7.
F.  Compilation fails due to an error on line 8.
G.  Compilation fails due to an error on line 9.

  27.  Given that FileNotFoundException extends IOException, and given:
 2. import java.io.*;
 3. public class MacPro extends Laptop {
 4.   public static void main(String[] args) {
 5.     new MacPro().crunch();
 6.   }
 7.   // insert code here
 8. }
 9. class Laptop {
10.   void crunch() throws IOException { }
11. }
   Which method(s), inserted independently at line 7, compile? (Choose all that apply.)
  A.  void crunch() { }
  B.  void crunch() throws Exception { }
  C.  void crunch(int x) throws Exception { }
  D.  void crunch() throws RuntimeException { }
  E.  void crunch() throws FileNotFoundException { }

  25.  Given:
 2. import java.util.*;
 3. public class Vinegar {
 4.   public static void main(String[] args) {
 5.     Set mySet = new HashSet();
 6.     do1(mySet, "0");  do1(mySet, "a");
 7.     do2(mySet, "0");  do2(mySet, "a");
 8.   }
 9.   public static void do1(Set s, String st) {
10.     s.add(st);
11.     s.add(Integer.parseInt(st));
12.   }
13.   public static void do2(Set s, String st) {
14.     s.add(st);
15.     s.add(Integer.parseInt(st));
16. } }
   Which are true? (Choose all that apply.)
  A.  Compilation succeeds.
  B.  Compilation fails due to an error on line 6.
  C.  Compilation fails due to an error on line 13.
  D.  Compilation fails due to an error on line 14.
  E.  Compilation fails due to an error on line 15.
  F.  If only the line(s) of code that don’t compile are removed, the code will run without exception.
  G.  If only the line(s) of code that don’t compile are removed, the code will throw an exception.

  33.  Given:
 1. public class LaSelva extends Beach {
 2.   LaSelva() { s = "LaSelva"; }
 3.   public static void main(String[] args) { new LaSelva().go(); }
 4.    void go() {
 5.     Beach[] ba = { new Beach(), new LaSelva(), (Beach) new LaSelva() };
 6.     for(Beach b: ba)  System.out.print(b.getBeach().s + " ");
 7.   }
 8.   LaSelva getBeach() { return this; }
 9. }
10. class Beach {
11.   String s;
12.   Beach() { s = "Beach"; }
13.   Beach getBeach() { return this; }
14. }
  What is the result?
A.  Beach LaSelva Beach
B.  Beach LaSelva LaSelva
C.  Beach LaSelva followed by an exception.
D.  Compilation fails due to an error at line 5.
E.  Compilation fails due to an error at line 6.
F.  Compilation fails due to an error at line 8.
G.  Compilation fails due to an error at line 13.
  35.  Given:
 3. public class Stealth {
 4.   public static void main(String[] args) {
 5.     Integer i = 420;
 6.     Integer i2;
 7.     Integer i3;
 8.     i2 = i.intValue();
 9.     i3 = i.valueOf(420);
10.     System.out.println((i == i2) + " " + (i == i3));
11. } }
   What is the result?
  A.  true true
  B.  true false
  C.  false true
D.  false false
E.  Compilation fails.
F.  An exception is thrown at runtime.

  36.  Given:
 2. import java.io.*;
 3. interface Risky {
 4.   String doStuff() throws Exception;
 5.   Risky doCrazy();
 6.   void doInsane();
 7. }
 8. class Bungee implements Risky {
 9.   public String doStuff() throws IOException { 
10.     throw new IOException(); 
11.   }
12.   public Bungee doCrazy() { return new Bungee(); } 
13.   public void doInsane() throws NullPointerException {
14.     throw new NullPointerException(); 
15. } }
   What is the result? (Choose all that apply.)
  A.  Compilation succeeds.
  B.  The Risky interface will not compile.
  C.  The Bungee.doStuff() method will not compile.
  D.  The Bungee.doCrazy() method will not compile.
  E.  The Bungee.doInsane() method will not compile.

1.   Given:
 1. abstract class Vibrate {
 2.   static String s = "-";
 3.   Vibrate() {  s += "v"; }
 4. }
 5. public class Echo extends Vibrate {
 6.   Echo() { this(7); s += "e"; }
 7.   Echo(int x) { s += "e2"; }
 8.   public static void main(String[] args) {
 9.     System.out.print("made " + s + " ");
10.   }
11.   static {  
12.     Echo e = new Echo();
13.     System.out.print("block " + s + " "); 
14. } }
    What is the result?
  A.  made -ve2e
  B.  block -ee2v
  C.  block -ve2e
  D.  made -eve2 block -eve2
  E.  made -ve2e block -ve2e
  F.  block -ve2e made -ve2e
  G.  block -ve2e made -ve2eve2e
  H.  Compilation fails.

4.   Given:
 3. import java.util.*;
 4. public class VC {
 5.   public static void main(String[] args) {
 6.     List x = new ArrayList();
 7.     Integer[] a = {3, 1, 4, 1};
 8.     x = Arrays.asList(a);
 9.     a[3] = 2;
10.     x.set(0, 7);
11.     for(Integer i: x) System.out.print(i + " ");
12.     x.add(9);
13.     System.out.println(x);
14. } }
A.  Compilation fails.
B.  3 1 4 2 [7, 1, 4, 1]
C.  3 1 4 2 [7, 1, 4, 2]
D.  7 1 4 2 [7, 1, 4, 2]
E.  3 1 4 2 [7, 1, 4, 1, 9]
F.  3 1 4 2 [7, 1, 4, 2, 9]
G.  7 1 4 2, followed by an exception.
H.  3 1 4 2, followed by an exception.

5.   Given:
 3. public class Honcho {
 4.   static boolean b1 = false;
 5.   static int z = 7;
 6.   static Long y;
 7.   public static void main(String[] args) {
 8.     for(int i = 0; i < 4; i++)
 9.       go(i);
10.   }
11.   static void go(int x) {
12.     try {
13.       if((x == 0) && (!b1 && z == 7)) System.out.print("0 ");
14.       if(x < 2 ^ x < 10) System.out.print("1 ");
15.       if((x == 2) && 
            (y == null | (y.longValue() == 0))) System.out.print("2 ");
16.       if(z
17.     }
18.     catch(Exception e) { System.out.print("e "); }
19. } }
   What is the result?
A.  0 1 2 3
B.  1 e 1 3
C.  0 1 e 1 3
D.  0 1 1 1 1 3
E.  1 1 1 2 1 3
F.  0 1 1 1 2 1 3
G.  Compilation fails.

Cockroach Theory

At a restaurant, a cockroach suddenly flew from somewhere and sat on a lady. She started screaming out of fear. With a panic stricken face and trembling voice, she started jumping, with both her hands desperately trying to get rid of the cockroach.

Her reaction was contagious, as everyone in her group also got panicky.

The lady finally managed to push the cockroach away but …it landed on another lady in the group.

Now, it was the turn of the other lady in the group to continue the drama.

The waiter rushed forward to their rescue.
In the relay of throwing, the cockroach next fell upon the waiter.

The waiter stood firm, composed himself and observed the behavior of the cockroach on his shirt.
When he was confident enough, he grabbed it with his fingers and threw it out of the restaurant.

Sipping my coffee and watching the amusement, the antenna of my mind picked up a few thoughts and started wondering, was the cockroach responsible for their histrionic behavior?
If so, then why was the waiter not disturbed? He handled it near to perfection, without any chaos.

It is not the cockroach, but the inability of the ladies to handle the disturbance caused by the cockroach that disturbed the ladies.

I realized that, it is not the shouting of my father or my boss or my wife that disturbs me, but it’s my inability to handle the disturbances caused by their shouting that disturbs me.

It’s not the traffic jams on the road that disturbs me, but my inability to handle the disturbance caused by the traffic jam that disturbs me.

More than the problem, it’s my reaction to the problem that creates chaos in my life.


Lessons learnt from the story:
I understood, I should not react in life. I should always respond.
The women reacted, whereas the waiter responded.

Reactions are always instinctive whereas responses are always well thought of, just and right to save a situation from going out of hands, to avoid cracks in relationship, to avoid taking decisions in anger, anxiety, stress or hurry.

Pebble Story

Many years ago a farmer in London had the misfortune to owe a huge sum to a money lender.The Moneylender, who was old and ugly, fancied the farmer's beautiful daughter. So he proposed a bargain.

He said he would forget the farmer's debt if he could marry his daughter.
Both the farmer and his daughter were horrified by the proposal. So the cunning money-lender suggested that they let providence decide the
matter.

He told them that he would put a black pebble and a white pebble into an
empty money bag. Then the girl would have to pick one pebble from the
bag.

If she picked the black pebble, she would become his wife and her father's debt would be forgiven.
If she picked the white pebble she need not marry him and her father's debt would still be forgiven.
But if she refused to pick a pebble, her father would be thrown into jail.

They were standing on a pebble strewn path in the farmer's field. As they talked, the moneylender bent over to pick up two pebbles. As he picked them up, the sharp-eyed girl noticed that he had picked up two black pebbles and put them into the bag.

He, then, asked the girl to pick a pebble from the bag.

Now imagine that you were standing in the field. What would you have
done if you were the girl? If you had to advise her, what would you have
told her?

Careful analysis would produce three possibilities:

The girl should refuse to take a pebble.
The girl should show that there were two black pebbles in the bag and expose the money-lender as a cheat.
The girl should pick a black pebble and sacrifice herself in order to save her father from his debt and imprisonment.

Take a moment to ponder over the story. The above story is used with the hope that it will make us appreciate the difference between lateral and logical thinking.

The girl's dilemma cannot be solved with traditional logical thinking.
Think of the consequences if she chooses.

The above logical answers.
What would you recommend to the girl to do?

Well, here is what she did:

The girl put her hand into the moneybag and drew out a pebble. Without looking at it, she fumbled and let it fall onto the pebble-strewn path where it immediately became lost among all the other pebbles.
"Oh, how clumsy of me," she said. "But never mind, if you look into the bag for the one that is left, you will be able to tell which pebble I picked."

Since the remaining pebble is black, it must be assumed that she had picked the white one. And since the money-lender dared not admit his dishonesty, the girl changed what seemed an impossible situation into an extremely advantageous one.


MORAL OF THE STORY:Most complex problems do have a solution. It is only that we don't attempt to think.

Challenging C Interview Objective Questions



1. void main()

{

char s[ ]="man";

int i;

for(i=0;s[ i ];i++)

printf("\n %c", i[s] );

}//What is o/p?

(A)man (B) nam

(C)mmm (D)compilation error



2. main( ){

static int var = 5;

if(--var)

main();

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

}//What is o/p?

A)0 1 2 3 4 B)1 2 3 4 5

C) compile error D)0 0 0 0 0

3. main() {

printf("\rbba");

printf("\baab");

printf("\raa");

}//What is o/p?

A) aa B)aaaab

C)aabab D)bbaaa



4. void main()

{

char str[] = "Hello World";

display(str);

}

void display(char *string)

{

printf("%s",string);

}//What is o/p?

(A)Hello World (B) Hello

(C)H (D)Compilation Error

5. void main()

{

int a[3][2][2] = { {1,2,3,4}, {5,6,7,8},{9,10,11,12} };

int *p,*q;

p=&a[3][2][2];

*q=***a;

printf("%d-%d",*p,*q);

}//What is o/p?

(A)12-1 (C)9-1

(C)1-12 (D)None of these

6. #define f(a,b) a/b

void main() {

int x=5,y=6;

printf("\n%d",f(x*6,y*x));

}//What is o/p?

(A)1 (B)25

(C)30 (D)None of these

7. void main( ) {

char *ch="Computer ";

while(*ch!='\0') {

++*ch;

printf("%c ",*ch); ch ++; }

}//What is o/p?

(A)Dpnqvufs (B)Donpvtfr

(C)Cpmquues (D)None of these

8. void main( ) {

static char names[5][7]={"pascal","java","cobol","fortran","perl"};

int i;

char *ch;

ch=names[3];

names[3]=names[4];

names[4]=ch;

printf("%s",names[4]);

}

(A)Compilation Error : Array index out of Bound

(B)Compilation Error: char Array is constant Pointer

(C)fortran

(D)perl



9. void main( ) {

int x=10,y=10,*p1,*p2,k;

p1=&x;

p2=&y;

k=5 + *p1 /*p2;

printf(“%d”,k);

}

A)6 B)5 c)Compile Error d)None of these

10. main( ) {

char *q;

int j;

for (j=0; j<3; j++) scanf(“%s” ,(q+j));

printf(“%s” ,(q));

}//Input are:ASPIRE,JAVA,OCJP

(A)AJOCJP (B)ASPIRE

(C)OCJP (D)None of these

11. void main ( ) {

static char *ch[ ] = {"black", "white", "yellow", "violet"};

char **ptr[ ] = {ch+3, ch+2, ch+1, ch}, ***p;

p = ptr;

**++p;

printf(" %s",(*--*--p + 4));

}

(A)ow (B)et

(B)k (D)e

12. f2(a,b)

int a;

float b; {

return( a = !(a==b) );

}

void main() {

int p1(), f2();

printf("The value is %d \n ",p1(f2,6,6.0));

}

p1(f2,val1,val2)

int (*f2) ();

int val1;

float val2;

{

return((*f2) (val1,val2));

}

(A) The value is 0 (B) The value is 1

(C) The value is 0.0 (D)Compilation Error



13. f(int n) {

If(n>0) return (n + f(n-1));

}

void main() {

printf(“%d”,f(10));

}

(A)55 (B)110

(C)45 (D)compilation error

14. void main() {

Char *ch = “hello”;

printf(ch);

}

(A) hello (B) compilation error

(C)run time error (D) None of these

15. void main(){

int x=1,y=0;

if (++x > 2)

if(++y<5)

y=100;

else

x=100;

printf(“ %d %d”, x,y);

}

A)100 0 B)100 100 C)100 2 D)None of these





16. what is the output of following?

void main(){ printf("%d",1||2); }

a. error b .1 c. 3 d. None of these

17. What is the output of following ?

void main(){

int i=100, j=200 , k=300;

printf("%d ,%d" ) ; }

a. 200,300 b. 300,200 c. 100,200 d .error

18.What is the output of following ?

abc(int i){

printf("%d",i); }

void main(){

abc((200,100)); }

a. 200 b . 100 c . compile time error d. run time error

19.What is the output of following ?

void main() {

abc() ; }

abc(){

printf("Hello");}

a. error of no prototype b. warning c . Hello d. Both b & c

20. What is the output of following code ?

void main(){

printf("ab\b"); printf("ab\r"); printf("a"); }

a. aaa b. abb c. aba d.None

21.What is the output of following code ?

void main(){

int far *p,*q;

int c;

c=sizeof(p)*sizeof(q)*sizeof(4); printf("%d",c);}

a. 4 b. 32 c. 8 d. 16

22.What is output ?

void main(){

int i=5;

printf("%d",(i++ + ++i) || (++i + ++i));

printf(" %d",i);}

a. 1 9 b. 1 6 c. 1 7 d. compiler dependent

23.What is the output?

#define fun(x,y) (x##y)

void main(){int i

;i=fun(200+5,5+200);

printf("%d",i); }

a. run time error b. 1 c. 455 d. 205205

24.What is output ?

void main (){int x ; printf("%d",x=10);}

a. Error b. 10 c. 1 d. garbage value

25.What is the output ?

void main()

{ int a,b=0;

if( a=b=0 )

printf (" Hello ");

else

printf ("World"); }

a. Hello b. World c. compile error d. Runtime error

26.Waht is the output ?

void main(){

int i,j,k;

printf("%d",printf("%d",scanf("%d", &j)*scanf("%d",&i))); }// input is i=10 j=10

a. 100 b. 11 c. 1 d. 0

27-What is output of following ?

void main(){

static int i;

for( ; i++ ; printf("%d ", i) );

printf("%d",i); }

a. infinite loop b. error c. 0 d. 1

28-int testarray [3] [2] [2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

What value does testarray [2][1][0] in the sample code above contain?

a. 3 b. 5 c. 7 d. 11

29-void myFunc (int x) {

if (x > 0)

myFunc(--x);

printf("%d, ", x); }

int main() { myFunc(5); return 0; }

What will the above sample code produce when executed?

a. 1, 2, 3, 4, 5, 5, b. 4, 3, 2, 1, 0, 0 c. 5, 4, 3, 2, 1, 0, d. 0, 0, 1, 2, 3, 4,

30-11 ^ 5

What does the operation shown above produce?

a. 1 b. error c. 5th power of 11 d. 14

31-What is the output of following

#define man(x,y) x>y?x:y;

void main(){

int i=10 , j ,k;j=5;k=0;

k=man ( i++ , ++j );

printf("%d %d %d",i,j,k);}

a. 12 6 11 b. 11 6 10 c. 11 6 11 d. 12 6 10

32-What is the output of following ?

#define mess junk

void main(){ printf("mess"); }

a. mess b. junk c. meshjunk d. error that mess cant be used in printf

33-Wha is the output of following ?

void main() { int g=300*300/300; printf("%d",g); }

a. 300 b. 81 c. error d. 1

34-#define square(x) x*x

void main(){ int i=10, j=5 ,k=0; k=square(i-j); printf("%d",k); }

a. 25 b. 45 c. 75 d. 0

35-What is the output of following?

void main(){ int i=024; printf("%d",i); }

a. 24 b. 024 c. 20 d. None

33-What is the output of following ?

void main(){

char *p; p="He"LL"o"; printf("%s",p); }

a. he"LL"o b. HeLLo c. error d. He

34-What is output ?

abc(){

int a;

if(1>0)

return 1;

a=100;

a++;

return ++a;}

void main(){

int i ; i=abc(); printf("%d",i);}

a. 1 & 1 warning b. 1 & 2 warning c. 1 & 3 warning d. 111

35- What is the output ?

abc(int i){ return i; }

void main(){

int i; i=abc(printf("Hello World")); printf("%d",i); }

a. 11 b. error c. 12 d. None

//36-What is the output ?

void main(){

char far* near* str; printf("%d",sizeof(str)); }

a. 2 b. 4 c. error d. 1

37-What is the output ?

void main(){

const int i; int k=10; i=100; k=++k + i; printf("%d",k); }

a. 111 b. error c. 112 d. None

38-What is the output ?

#define printifless(x,y) if(x<y) printf("%d",x)

void main(){

int i=2,k=1;

if(i>0 && k>0)

printifless(i,k);

else

printf("A"); }

a. A b. nothing c. error d. 2

39-What is the output ?

void main(){

int a=10,b=20,c=30,d=40;

if(a,b,c,d)

printf("Hello"); }

a. Hello b. error c. warning d. Hello10203040

40-What is the output?

main(){

int i=100,j=10,k;

int *p=&j; k=i/*p;

printf("%d",k);}

a. 10 b. error c. warning d. 1

41-What is the output?

main(){

extern int i ; i=20; printf("%d",i);}

a. compile error b. runtime error c. linker error d. 20

42-What is the output ?

main(){

int i=-1 ,j=-1,k=0,l=2,m;

m=i++ && j++ && k++ || l++;

printf("%d %d %d %d %d",i,j,k,l,m);}

a. error b. 0 0 1 3 1 c. 0 0 1 3 2 d. warning

43- main(){

static int i;

switch(i) {

default:printf("garbage");

case 0: printf("Zero"); break;

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

case 2: printf("two"); break; } }

a. error b. zero c. garbage zero d. zero grabage

44-What is output ?

main(){

printf("%x",-1<<4);}

a. ff00 b. ffff c. 240 d. None

//45-What is output ?

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

a. 54554 b. 45545 c. 54454 d. 45445

46-.What is the output ?

#define square(x) x*x

main(){

int i;

i = 64/square(4);

printf("%d",i);}

a. 16 b. 64 c. 4 d. error

47-Size of structure can be determined by

1-sizeof(variablename) 2-sizeof(struct tag)

a. only 1 b. only 2 c. both 1 & 2 d. none

48-What is the output ?

main(){

printf("%p",main);}

a. some address b. undefined symbol error c. 0xfa d. None

49-#define int char

main(){

int i=65;

printf("%d",sizeof(i));}

a. error b. 1 c. 2 d. 0

50-What is the output ?

main(){

char string[]="Hello World";

display(string);}

void display(char *string){

printf("%s",string);}

a. "Hello World" b. Hellow World c. error d. warning & Hello World



3. main( ) {

float c[]={1,2.2,3.2};

float i,*p=c,*q=c;

for( i =0; i<3;i++,*q++;)

printf("%2.1f ",*c);

for(i=0 ; i<3 ; i++,(*p)++)

printf("%2.1f ",*p);

}//What is o/p?

A)1.0 2.2 3.2 1.0 2.2 3.2 B)1.0 1.0 1.0 1.0 2.2 3.2

C)1 2 3 1 2 3 D)1 1 1 1 2 3

14. void main() {

void f1();

void f2();

f1();

}

void f1() {

f2();

printf(“in f1”);

}

void f2() {

printf(“in f2”);

}//what is o/p?

(A) Compilation Error (B)in f2

(C) in f2in f1 (D)None of these

16. void main() {

char *p; int *q; long *r;

p=q=r=0;

p++; q++; r++;

printf("%p...%p...%p",p,q++,r++);

}

A)0001...0004...0008 B)0001...0002...0004

C)0001...0002...0002 D)0002...0004...0008

17-What is a difference between a declaration and a definition of a variable?

a. Both can occur multiple times, but a declaration must occur first.

b. A definition occurs once, but a declaration may occur many times.

c. A declaration occurs once, but a definition may occur many times.

d. Both can occur multiple times, but a definition must occur first.

28-What is the output ?

void main() { char *s="\12345s\n"; printf("%d",sizeof(s)) }

a. 7 b. 6 c. 8 d. 5