IQOD #5

Posts 1–7 of 7 · Page 1 of 1
IQOD #5
Consider the following code
Code:
int counter(int i)
{
	static int count = 0;
	count = count + i;
	return count;
}

void main()
{
	int i, j;
	for(i = 0; i <= 5;  i++)
		j = counter(i);
}
What is the value of J at the end of the program
0+(0+1+2+3+4+5)=15
The value of j is
<!--
5 ?
Because it goes through the loops about 6 times, but what was written previously gets overwritten with each iteration of the loop?

Wait, no Static, which means it should be 15?

I am sticking with 15, but "static int count = 0;", wouldn't that reset count back to 0 at the start of each loop?
-->
hey guys, remember me, my last account was zhhot, it got keylogged
Quote Originally Posted by [MPBH]Haxxor View Post
hey guys, remember me, my last account was zhhot, it got keylogged
you got keylogged? Poor you =(.
The Correct Answer is indeed 15!
Quote Originally Posted by B1ackAnge1 View Post
The Correct Answer is indeed 15!
Yeh the static modifier is pretty cool. Probably a good idea to create some function to clear count though.

And wow. ZZhot how did that happen?
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us