Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

ASSIGNMENT #24

Write a program to initialize an Array & Pointer.

PROGRAM:
#include<stdio.h> #include<conio.h> void main() { int h[5]={10,20,30,40,50}; int *s[5],d; clrscr(); for(int a=0;a<5;a++) { printf("THE ARRAY VALUE %d IS: %d\n",a+1,h[a]); } printf("\n\n\n"); for(d=0;d<5;d++) { s[d]=&h[d]; printf("THE POINTER VALUE %d IS: %d\n",d+1,*s[d]); } getche(); }

OUTPUT:
THE THE THE THE THE ARRAY ARRAY ARRAY ARRAY ARRAY VALUE VALUE VALUE VALUE VALUE 1 IS: 10 2 IS: 20 3 IS: 30 4 IS: 40 5 IS: 50

THE THE THE THE THE

POINTER POINTER POINTER POINTER POINTER

VALUE 1 IS: 10 VALUE 2 IS: 20 VALUE 3 IS: 30 VALUE 4 IS: 40 VALUE 5 IS: 50

ASSIGNMENT #25
Write a program to find Area using Pointer.

PROGRAM:
#include<stdio.h> #include<conio.h> void area(int r, float*a); void main(void) { clrscr(); int r; float a; printf("enter radius:"); scanf("%d",&r); area(r,&a); printf("area=%f",a); getche(); } void area(int r, float*a) { *a=3.14*r*r; }

OUTPUT:

enter radius:23 area=1661.060059

ASSIGNMENT #26
Write a program doing swapping using Pointer.

PROGRAM:
#include<stdio.h> #include<conio.h> void swap(int *x, int *y); void main(void) { int a=3,b=4; printf("a=%d",a); printf("b=%d",b); swap(&a,&b); printf("interchange value"); printf("a=%d",a); printf("b=%d",b); getche(); } void swap(int*x ,int*y) { int num; num=*x; *x=*y; *y=num; }

OUTPUT:
a=3 b=4 interchange value a=4 b=3

ASSIGNMENT #27
Write a program to find addresses.

PROGRAM:
#include<stdio.h> #include<conio.h> void main(void) { textcolor(blue); clrscr(); int a =4; gotoxy(5,5);cprintf("num = %d",a); gotoxy(5,8);cprintf("address=%d ",&a); gotoxy(5,10);cprintf("new address =%d",&a+4); getche(); }

OUTPUT:
num = 4 address=-12 new address =-4

You might also like