+ 2

C - Why k doesn't change?

#include <stdio.h> void func(int* x){ x-=5; } int main() { int k = 7; func(&k); printf("%d",k); return 0; }

30th Jun 2020, 12:04 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Antworten
+ 1
You forgot to dereference the pointer ( *x ) in the function. Now you're just decrementing the pointer itself. There are no calls by reference (&) in C, FradeAlencar. :)
30th Jun 2020, 12:27 PM
Dennis
Dennis - avatar
0
Ohhh, I read wrong, kkk I thought it was c ++, kkk sorry
30th Jun 2020, 12:39 PM
FradeAlencar
FradeAlencar - avatar