Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Interesting Interview Questions For C Programmer (http://www.go4expert.com/articles/interview-questions-c-programmer-t26825/)

lionaneesh 3Oct2011 07:12

Re: Interesting Interview Questions For C Programmer
 
OS : Windows 7
Compiler : Code:Blocks
Compiled Without problem

Code:

0
1
4
9
16

Process returned 0 (0x0)  execution time : 1.110 s
Press any key to continue.


poornaMoksha 3Oct2011 07:14

Re: Interesting Interview Questions For C Programmer
 
Can you give it a try on Unix/Linux ??

lionaneesh 3Oct2011 07:16

Re: Interesting Interview Questions For C Programmer
 
Quote:

Originally Posted by poornaMoksha (Post 87570)
Can you give it a try on Unix/Linux ??

Yeah Sure , I will! But can you explain me the reason why its giving error on Unix and not on Windows

poornaMoksha 3Oct2011 07:19

Re: Interesting Interview Questions For C Programmer
 
I dunno why its not giving any error on windows but logically when we are about to call free(), we have incremented the address held at pointer 'p' (as we have used p++ many times in loop). Now when we do a free, then 'p' contains a different address than what malloc() gave it. So ideally the program should crash at free().

lionaneesh 3Oct2011 18:23

Re: Interesting Interview Questions For C Programmer
 
Quote:

Originally Posted by poornaMoksha (Post 87572)
I dunno why its not giving any error on windows but logically when we are about to call free(), we have incremented the address held at pointer 'p' (as we have used p++ many times in loop). Now when we do a free, then 'p' contains a different address than what malloc() gave it. So ideally the program should crash at free().

I know that and yeah regarding the windows issue , I think my compiler provides some support for preventing memory leak ! Thats why no errors! :D

lionaneesh 3Oct2011 18:30

Re: Interesting Interview Questions For C Programmer
 
Quote:

Originally Posted by poornaMoksha (Post 87566)
Did you even try to execute it??

Can u please explain my other problems too! :)

poornaMoksha 3Oct2011 18:40

Re: Interesting Interview Questions For C Programmer
 
For problem '3', google how or rather in which order the function arguments are processed/passed when a function call is made.

hanleyhansen 12Oct2011 17:53

Re: Interesting Interview Questions For C Programmer
 
This is good stuff. Are you going to provide the answer to all the questions eventually?

poornaMoksha 12Oct2011 17:58

Re: Interesting Interview Questions For C Programmer
 
Quote:

Originally Posted by hanleyhansen (Post 87908)
This is good stuff. Are you going to provide the answer to all the questions eventually?

Thanks, I thought of having interactive sessions with different users on this article. If somebody comes up with some doubt/query then I'll definitely answer that but providing answers directly would defeat the purpose as of now. All I want is that anyone who finds these questions worth trying, should try them. Answers, doubts, queries can be discussed here.

jyothishwebtech 21Nov2011 15:51

Re: Interesting Interview Questions For C Programmer
 
It's a very interesting article.I like C program very much.So it's very helpfull to me.I can understand more programs&it's answer.


All times are GMT +5.5. The time now is 21:40.