Print Page | Close Window

Test01 Q12 CS output of given pgm!!!

Printed From: One Stop GATE
Category: GATE AT A GLANCE
Forum Name: Test Series
Forum Discription: Discuss various Test Series available in the market before joining one.
URL: http://forum.onestopgate.com/forum_posts.asp?TID=690
Printed Date: 07Feb2025 at 10:13am


Topic: Test01 Q12 CS output of given pgm!!!
Posted By: manju
Subject: Test01 Q12 CS output of given pgm!!!
Date Posted: 23Feb2007 at 2:48pm
 int i= 10;
void main()
{ int i=5;
printf(i);
{int i=2;
printf(i);
{i+=3;
printf(i);
}
i++;
printf(i);
}i+=3;
printf(i);
f();
}

f()
{
printf(i);
{ int i= 15;
printf(i);
}
}

Ans given is D: 5,2,5,6,8,10,15

how come 6 will be there ?? am i missing some scope rules??



Replies:
Posted By: balu
Date Posted: 23Feb2007 at 2:49pm
 Hi,

You are missing out scope..
int i=2;
First 3 gets added to it
Then it is printed and then incremented
So answer is 6

JAI HIND



Print Page | Close Window