r/learnprogramming • u/Expensive-Morning307 • Oct 10 '26
Was the question poorly done or am I an idiot?
So, I just took my first exam for C programming and I got all the true/false stuff correct however I didn't get a few of the code review segments correct. Upon review after the test I realized my error, however one confused me in terms of what I supposed to assume something that was never stated.
So the code snip-it was this
int z = 0;
int g = 0;
int s = 0;
int i = 0;
while (i < 50) {
scanf("%d", &t);
s = s +t;
if(t >= 0)
g = g +1;
else
z = z +1;
i = i + 1;
}
So the question asks how many times does this loop execute. I selected never as I saw there was no declaration statement for the t variable, so I assumed it would never run cause it would error out due to that. I got the question wrong, cause I was supposed to assume t was initialized? I think the answer is 50 if it was.
However, am I an idiot or was this question poorly typed out? Cause, I was confused initially by the coding examples on the exam cause the professor uses different syntax for C at times when compared to the textbook. IE: (&t) when the book used (, t) not & in any scan or print statements(which also initially confused me). Plus the header is usually not there in these coding samples on the exam.
So was I supposed to just assume the t variable not be declared was shorthand and I should have focused on what the loop actually did? I am assuming I am an idiot for assuming the answer was never because t as a variable was missing. However honestly I think it's still confusing to expect me not to think it was going to not run due to a undeclared variable error.