I'm trying to write a code to check with a pointer of int if a number is even or not.
My code is like that:
#include <stdio.h>
#include <string.h>
void isEven (int *isFlag, int num) {
if (num % 2 == 0) {
*isFlag = 1;
} else {
*isFlag = 0;
}
}
int main() {
int num = 4;
int *isFlag = 0;
isEven(isFlag, num);
printf("%d", isFlag);
}
But I get segmentation fault and I'm expected to see that isFlag = 1
, what is the problem in the code? (I know we can do it better but I'm trying to understand pointers)