#include<stdio.
h>
void swap(int *,int *);
int main()
int n1,n2;
printf("\n\n Function : swap two numbers using function :\n");
printf("------------------------------------------------\n");
printf("Input 1st number : ");
scanf("%d",&n1);
printf("Input 2nd number : ");
scanf("%d",&n2);
printf("Before swapping: n1 = %d, n2 = %d ",n1,n2);
//pass the address of both variables to the function.
swap(&n1,&n2);
printf("\nAfter swapping: n1 = %d, n2 = %d \n\n",n1,n2);
return 0;
void swap(int *p,int *q)
//p=&n1 so p store the address of n1, so *p store the value of n1
//q=&n2 so q store the address of n2, so *q store the value of n2
int tmp;
tmp = *p; // tmp store the value of n1
*p=*q; // *p store the value of *q that is value of n2
*q=tmp; // *q store the value of tmp that is the value of n1
Function : swap two numbers using function :
------------------------------------------------
Input 1st number : 2
Input 2nd number : 4
Before swapping: n1 = 2, n2 = 4
After swapping: n1 = 4, n2 = 2
#include <stdio.h>
//if the least significant bit is 1 the number is odd and 0 the number is
even
int checkOddEven(int n1)
return (n1 & 1);//The & operator does a bitwise and,
int main()
int n1;
printf("\n\n Function : check the number is even or odd:\n");
printf("------------------------------------------------\n");
printf("Input any number : ");
scanf("%d", &n1);
// If checkOddEven() function returns 1 then the number is odd
if(checkOddEven(n1))
printf("The entered number is odd.\n\n");
else
printf("The entered number is even.\n\n");
return 0;
Sample Output:
Function : check the number is even or odd:
------------------------------------------------
Input any number : 5
The entered number is odd.
Explanation:
int checkOddEven(int n1) {
return (n1 & 1); //The & operator does a bitwise and,