#include <stdio.h>
class C
{
public:
static int i;
static int j;
};
int i = 10;
int C::i = 20;
int C::j = i + 1;
int main ()
{
printf("%d", C::j);
return 0;
}
What is the value of: C::j
I was reading a c++ quiz and came across the following question. I thought that the answer is 11
.
int C::j = i + 1;
Since it is accessing the non static i
which is 10? So, I thought 11
should be the answer?
I compiled and ran this code through visual studio and it prints 21
. Which is confusing to me. Can someone please explain why this is happening? What am I missing?