Important : Please do NOT wait for job alert emails. Always directly visit www.ChetanaSforum.com to check all jobs DAILY.Important : We suggest you to SUBSCRIBE HERE to keep track of new jobs through Email. You will get only 1 Email per day.

 Infosys, TCS, Yahoo & Amazon are hiring. Register Now ! Submit Resume to 45,000 Recruiters Apply for 52,000 jobs in India

 c predict output, Tcs Interview question
Apr 18 2010, 11:45 AM
Post #1

Group: Members
Posts: 86
Joined: 6-November 09
Member No.: 247,312

 Apply for 52,000+ jobs in India ! Post Your Resume ! Infosys, TCS, Yahoo & Amazon are hiring. Register Now !
 If you like this post, please share it to help others.

void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=&sum;
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}

If possible explain also

--------------------
ankit
 Apr 18 2010, 01:12 PM Post #2 Advanced Member Group: Members Posts: 86 Joined: 6-November 09 Member No.: 247,312 any one who can answer? -------------------- ankit
 Apr 18 2010, 06:04 PM Post #3 Newbie Group: Members Posts: 1 Joined: 17-March 10 From: Chennai Member No.: 292,682 QUOTE (ankit chitkara @ Apr 18 2010, 12:45 PM) void main(){int count=10,*temp,sum=0;temp=&count;*temp=20;temp=∑*temp=count;printf("%d %d %d ",count,*temp,sum);}If possible explain alsovoid main(){int count=10, sum=0;int *temp;temp=&count;// here u r assigning address of count to temp. *temp=20;//temp is pointing to count now. *temp means value at temp. the value at temp is count. so count is 20 now.temp=∑//overwriting the content of temp with address of sum*temp=count;//count value is 20 as mentioned earlier. now *temp is pointing to sum. so sum will be assigned as 20.printf("%d %d %d ",count,*temp,sum);//all are 20 here.}
 Apr 18 2010, 06:51 PM Post #4 Advanced Member Group: Members Posts: 86 Joined: 6-November 09 Member No.: 247,312 nice answer Keep it up -------------------- ankit
 Mar 13 2012, 12:32 PM Post #5 Newbie Group: Members Posts: 1 Joined: 13-June 10 Member No.: 340,235 QUOTE (ankit chitkara @ Apr 18 2010, 01:12 PM) any one who can answer?void main(){int count=10, sum=0;int *temp;temp=&count; //Now temp will point the address of count variable. *temp=20; //We are assigning the value to the address which temp is pointing, so the changes will reflect in count variable,bcoz temp pointing to the count variabletemp=∑ //Again we are assigning the new address to temp, so now temp will point the address of sum.*temp=count; //value of count variable is 20 & it will assign to sum variable(look at just above line).printf("%d %d %d ",count,*temp,sum); //all will be 20.}

 Lo-Fi Version Time is now: 20th June 2013 - 11:27 AM