tag:blogger.com,1999:blog-7764585372415707340.post1801416693209850158..comments2023-07-10T06:58:24.777-07:00Comments on C Programming World: c aptitute questions with explained answersAnonymoushttp://www.blogger.com/profile/10628525500832863894noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7764585372415707340.post-58743468834102303932011-08-11T04:48:34.355-07:002011-08-11T04:48:34.355-07:00Hi,
Your answer is incorrect
This can be better u...Hi,<br />Your answer is incorrect<br /><br />This can be better understood in C++<br />struct A<br />{<br /> A()<br /> {<br /> printf("A()\n");<br /> }<br /> ~A()<br /> {<br /> printf("~A()\n");<br /> }<br /> int i;<br />};<br />int _tmain(int argc, _TCHAR* argv[])<br />{<br /> A *i=0;<br /> {<br /> A a;<br /> i=&a;<br /> i->i=10;<br /> }<br /> printf(" %d ",i->i);<br /> return 0;<br />}<br /><br />as you can see that the variable i is still accessed after the object has gone out of scope (that its destructor has been called)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7764585372415707340.post-85233346333300829452011-08-09T12:39:31.061-07:002011-08-09T12:39:31.061-07:00Q6 explaination is right..
read about "dangli...Q6 explaination is right..<br />read about "dangling pointers"...there is a concept of dangling pointers in that..not..operating system or 4k memory.Aman Vermahttps://www.blogger.com/profile/02868858787701797702noreply@blogger.comtag:blogger.com,1999:blog-7764585372415707340.post-36540484300426475842011-08-09T01:18:18.216-07:002011-08-09T01:18:18.216-07:00incorrect explaination for Q6
"The variable ...incorrect explaination for Q6<br /><br />"The variable i is a block level variable and the visibility is inside that block only. But the<br />lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the<br />i is still allocated space, *j prints the value stored in i since j points i. "<br /><br />This is not true, it prints the value 10 even though this variable has been deallocated, the reason is that the OS does not claim that memory segment for every few bytes that are not in use, it only claims memory in multiple of 4K (for 32-bit systems)Anonymousnoreply@blogger.com