Pointers and function:
Call by value:
/* Include <stdio.h>
void main()
{
int x,y;
x=20;
y=30;
printf(“n Value of a and b before function call =%d %d”,a,b);
fncn(x,y);
printf(“n Value of a and b after function call =%d %d”,a,b);
}
fncn(p,q)
int p,q;
{
p=p+p;
q=q+q;
}
Call by Reference:
/* example of call by reference*?
/* Include <stdio.h>
void main()
{
int x,y;
x=20;
y=30;
printf(“n Value of a and b before function call =%d %d”,a,b);
fncn(&x,&y);
printf(“n Value of a and b after function call =%d %d”,a,b);
}
fncn(p,q)
int p,q;
{
*p=*p+*p;
*q=*q+*q;
}
Bubble sort in pointers
#include <stdio.h>
int arr[10] = { 3,6,1,2,3,8,4,1,7,2};
void bubble(int a[], int N);
int main(void)
int i;
putchar('\n');
for (i = 0; i < 10; i++)
printf("%d ", arr[i]);
bubble(arr,10);
putchar('\n');
for (i = 0; i < 10; i++)
printf("%d ", arr[i]);
return 0;
}
void bubble(int a[], int N)
int i, j, t;
for (i = N-1; i >= 0; i--)
for (j = 1; j <= i; j++)
if (a[j-1] > a[j])
t = a[j-1];
a[j-1] = a[j];
a[j] = t;
Pointer to arrays:
/* A program to display the contents of array using pointer*/
main()
{
int a[100];
int i,j,n;
printf(“nEnter the elements of the arrayn”);
scanf(“%d”,&n);
printf(“Enter the array elements”);
for(I=0; I < n; I++)
scanf(“%d”,&a[I]);
printf(“Array element are”);
for(ptr=a; ptr < (a+n); ptr++)
printf(“Value of a[%d]=%d stored at address %u”,j+=,*ptr,ptr);
}
#include
int main()
printf("size of a short is %d\n", sizeof(short));
printf("size of a int is %d\n", sizeof(int));
printf("size of a long is %d\n", sizeof(long));
#include <stdio.h>
#include <conio.h>
main() {
clrscr();
int *array[3];
int x = 10, y = 20, z = 30;
int i;
array[0] = &x;
array[1] = &y;
array[2] = &z;
for (i=0; i< 3; i++) {
printf("The value of %d= %d ,address is %u\t \n", i, *(array[i]),
array[i]);
}
getch();
return 0;
}