C Program to check number is even or odd using call by reference
In this program, You will learn how to check number is even or odd using call by reference in c.
Call by Reference
void check(int n, int *p){
statement
}
Example: How to check number is even or odd using call by reference in c.
#include<stdio.h>
void check(int n, int *p) {
if( n % 2 == 0){
*p = 1;
}else{
*p = 0;
}
}
int main() {
int n, p = 1;
printf("Enter a number:");
scanf("%d", &n);
check(n, &p);
if (p == 1) {
printf("Number is even:%d", n);
} else {
printf("Number is odd:%d", n);
}
return 0;
}
Output:
Enter a number:20
Number is even:20