Professional Documents
Culture Documents
R13 Syllabus
5.2:*p1*p2
5.3:*p2temp
Step 6 : Display the values of a and b after interchange.
Step 7 : Stop.
FLOWCHART:
START
p1&a
p2&b
temp*p1
*p1*p2
*p2temp
Display a and b
STOP
PROGRAM
/* C Program To Interchange values of two integers using pointer based functions */
Program name:
// wk14a.c
/* Done By : C-Faculty
Dated: 15/10/2013*/
#include<stdio.h>
#include<conio.h>
void main()
scanf("%d%d",&a,&b);
p1=&a;
// Assign p1 to address of a
p2=&b;
// Assign p2 to address of b
temp=*p1;
*p1=*p2;
// Assign a to value of b
*p2=temp;
getch();
20
30
20
286
594
286
ORIGINAL OUTPUT :
Output (1)
Enter any two values 100
200
100
212
102
2. What is a parameter?
Ans:
Parameters are also known as arguments.They are used to communicate data between the
calling function and the called function.
The parameters are of two types:
SPECIFICATION:
(14)(b) Write a C program to swap two numbers using pointers.
DESCRIPTION:
Pointer is a user defined data type which creates special types of variables which can hold
the address of primitive data type like char, int, float, double or user defined data type like function,
pointer etc. or derived data type like array, structure, union, enum.
ALGORITHM:
Step 1 : Start
Step 2 : Initialize the variables x,y.
Step 3 : Display the x and y values before swapping
Step 4 : Call swap( )
Step 5: Display the x and y values after swapping
Step 6 : Stop
Algorithm for swap() function :
Step 1 : Begin
Step 2: Declare a temporary variable temp of type int.
Step 3 : Assign temp *a
Step 4: Assign *a *b
Step 5 : Assign *b temp
Step 6 : End
FLOWCHART:
START
swap(&x,&y )
Read a third
variable temp
temp*a
*a*b
*btemp
STOP
PROGRAM
/* C Program To swap two numbers using pointers */
Program name:
// wk14b.c
void main()
//
clrscr();
printf("After swapping :x=%d y=%d\n\n",x,y); // Display the values of x & y after swapping
getch();
temp=*a;
*a=*b;
// Assign x to value of y
*b=temp;
}
./a.out
y=200
y=100
ORIGINAL OUTPUT :
Output (1)
Before exchange: x=10
y=20
y=10
Output (2)
Before exchange: x=15
y=29
y=15
Formal parameters
The formal arguments
are the
parameters/arguments
in a function
declaration.
Formal arguments
belong to the called
function.