A hypothetical interview

In this post am going to write an interview happened recently. Here it goes.

Interviewer: Hi.

Interviewee: Hi.

Interviewer reads the resume forwarded by the interviewee. Interviewer thinks for a while and sees that interviewee is a fresher. So he decides to ask some basic questions.

Interviewer: Can you write a C program which outputs the fibonacci series?

Interviewee: Yah sure

And then interviewee starts writing a program. He wrote an iterative program.

Interviewer: Good. Can you write the same using recursion? Just write the function.

The interviewee wrote the program, as if the the answer was at the tip of his pen.

Interviewer: Good. Can you explain how a recursion works. I mean using a diagram.

Interviewee started drawing rectangular blocks and started explaining the main function(which was written in a rectangular block) will call the function foo(which was written in another rectangular block). He continued by saying function foo will call foo again and so on.

Interviewer: Do you know what is a stack?

Interviewee: Yes sir. It’s the one which has the push and pop operation.

Interviewer: Can you explain the recursion using the data structure stack?

Interviewee thinks for a while and says he needs time to think. The interviewer agrees and asks him to take his time. Finally interviewee replies,”No sir its difficult for me explain πŸ™ “.

Interviewer: Thats ok. Cheer up. Can you write a small program where both the if and the else part of the program gets executed?Β  I mean if you have a printf function inside if and else, both should get printed πŸ™‚ .

Interviewee: Yah. (Now the interviewer is happy). Lets say you have c=1, and

if(c == 1){ printf(“a”);}

else{printf(“b”);}

Interviewer: This would print either a or b. But what if I wanted to print both a and b?

Interviewee: No. It cannot be done.

Interviewer: Ok. Do you know what is a system call? Have you used any system call in your program?

Interviewee: Yah I have heared about system calls. I know 5 system calls. No I haven’t used any system call in my program.

Interviewer: Ok. Can you mention any 3 of them?

Interviewee: Sorry sir I forgot.

Interviewer: Its ok. Have you heared about open function?

Interviewee: No sir. I have heared about fopen.

Interviewer: That’s ok. If you know what is fopen you can try for open too πŸ™‚

Interviewee: Ahh… Open function will open a file. If the file is not there it will create it.

Interviewer: What is the return value of open function?

Interviewee: zero. An integer.

Interviewer: Zero!!! Are you sure? Did you made a guess? If not can you explain how it returns zero?

Interviewee: It returns zero because zero is at the top of the stack. And zero doesn’t consume memory.

Interviewer: Just now you told that it returns an integer. And now you say zero doesn’t requires memory. Can you elaborate on this?

Interviewee: Zero is expressed as 0000 so it requires no memory.

Interviewer: What isΒ  the size of an integer?

Interviewee: Its 2 bytes.

Interviewer: Humm. Have you heared about a system call fork?

Interviewee: Yah I had heared about it. It creates a child process.

Interviewer: Ok. You got it. I hope you know what it returns.

Interviewee: It returns 1.

Interviewer: 1, for what?

Interviewee: It returns one when you call fork function. In a stack it will be next to zero.

Interviewer: What if its 100?

Interviewee: It may be the 99th position. But generally it doesn’t happen because from zero to 98, the memory will be wasted.

Interviewer thinks,”Memory wasted? Ok. Thats his thinking”.

Interviewer: Ok now can you write the program which prints both a and b of if and else, using fork?

Interviewee: Yah.

void fork(){

int c=1;

if (c == 1) { printf(“a”);}

else{printf(“b”);}}

Interviewer: Oh. Again it may print either a or b. But dude, the function name you had used is fork. Will it compile if you are using a gcc compiler?

Interviewee: Yah it will. Sorry sir I don’t know how to write this program.

Interviewer: Its ok. Do you know bitwise operators in c?

Interviewee: Yah. right shift, leftshift etc.

Interviewer: Ok. Can you tell me the output of 101 + 001(i.e 5 + 1)

Interviewee: Yes sir the output is 011.

Interviewer: How did you got it?

Interviewee: I took the 2’s complement of 101 and added 1 to it.

Interviewer: Dude what is the decimal of the binary 101 and 1?

Interviewee: Its 5 and 1.

Interviewer: Now add 5 and 1. What will be decimal output and convert it into binary?

Interviewee: Its 6. And binary representation of decimal 6 is 110. Oops sorry sir.(Interviewer understood his fault)

Interviewer: It’s ok buddy. Can you write a program to find out whether a number is even or odd? Don’t write function as such. Just show me the condition where you are going to check it.

Interviewee: Yes sir. a is the number which holds the number.

if((a % 10)==0)

Then a is even.

Interviewer: So you mean to say that 10 and multiples of 10 are even. And others are odd.

Interviewee: Yes sir.

Interviewer: Ok tell me whether 2 is even or odd.

Interviewee: 2 is the least even number. I will catch 2 before the if condition mentioned above.

Ineterviewer: Oh. Then what about 3?

Interviewee: 3 is odd.

Interviewer: Could you explain the reason for that?

Interviewee: 3 has only 2 divisor. 3 and 1.

Interviewer: What about 4?

Interviewee: 4 is odd, because 4 has 3 divisors. 1, 2 and 4.

Interviewer: Ok. What about 5,6,7,8 and 9?

Interviewee: Sir this holds for all these numbers. Similar for 9 too.

Interviewer: Ok. What do you call a number that is divisible by 2?

Interviewee: Odd number.

Interviewer: I think you are confused with composite numbers?

Interviewee: No sir. I am sure I am talking about even and odd numbers.

Interviewer: Ok sir. I am finsished.

Its recision going on everywhere. Most of the economic zones are affected by the recision. Many companies are doing lay offs. At this point of time if some one gives answers like this will an interviewer be push him to other rounds of interview or not?

I came across some others blog like Viveks and Atanus, which clearly tells how our education system is spawning new engineers and research fellows.

Comments (3)

YaSjFebruary 2nd, 2009 at 11:43 pm

πŸ™‚

NikanthApril 29th, 2009 at 10:20 pm

Interesting read. Thanks

[…] A hypothetical interview – Sujith S […]

Leave a comment

Your comment