Hi guys
I'm working on the issue to understand pointers and addresses in c programming.
Unfortunately I don't see the problem here. For a c programmer my question should be easy to response
Code:
#include<stdio.h>
void factorial(int*);
int main()
{
// the program calculates faculty
int n;
int *pn;
printf("Enter a positive integer which you want to facultate\n");
scanf("&d",&n);
pn = &n;
factorial(pn);
printf("result: %d", n);
return 0;
}
void factorial(int *px)
{
int k,tmp;
tmp = *px;
if( *px == 0)
tmp = 1;
for (k=1;k<=*px;k++)
tmp = tmp * k;
*px = tmp;
}
I can build/compile the file. But the result is: 3265920 for every positve integer I want to facultate ..
thx for helping me!
Matts