A pointer problem from a high school programming contest
Hi experts,
The code below is from a programming contest, the answer must be given without using a compiler(this test is on paper).
The problem: How many '*' does that piece of code prints?
a) 20
b) 25
c) 33
d) 50
e) 100
Code:
#include<cstdio>
void f(int i){i--;}
void g(int i){int*p;p=&i;*p--;}
void h(int*p){*p--;}
void i(int*p){int i;i=*p;i--;}
int main()
{
int index=100;
for(;index>0;index--)
{ printf("*"); f(index); g(index); h(&index); i(&index); }
}
I found out 50, but when i put it in compiler i saw that i'm mistaken, the answer seems 100. How can it be? shouldn't function h decrease index too?
thanks in advance!