Read OnLine Cpp Program Example
POINTER | |
---|---|
PRAC 3 | PRAC 4 |
//wap to print swaping of a two number #include<iostream.h> #include<conio.h> void swap(int a,int b) { int c; clrscr(); cout<<"\n Before swap a=%d",a; cout<<"\n Before swap b=%d",b; c=a; a=b; b=c; cout<<"\n After swap a="<<a; cout<<"\n After swap b="<<b; } void main() { int x,y; x=5; y=6; swap(x,y); getch(); } ----------output----------- Before swap a=5 Before swap b=6 After swap a=6 After swap b=5 |
//wap to print swaping of a two number #include<iostream.h> #include<conio.h> void swap(int *a,int *b) { int c; clrscr(); cout<<"\n Before swap a="<<*a; cout<<"\n Before swap b="<<*b; c=*a; *a=*b; *b=c; cout<<"\n After swap a="<<*a; cout<<"\n After swap b="<<*b; } void main() { int x,y; x=5; y=6; swap(&x,&y); getch(); } -------output------- Before swap a=5 Before swap b=6 After swap a=6 After swap b=5 |
Previous | Next |
Download | Download |