0% found this document useful (0 votes)
25 views4 pages

Assignment #24: Program

The document contains 4 programming assignments involving arrays and pointers in C language. The first assignment initializes an array and assigns its elements to pointer variables to print their values. The second assignment calculates the area of a circle using a pointer to pass the result by reference. The third assignment swaps the values of two variables by passing their addresses to a function using pointers. The fourth assignment prints the address of a variable and demonstrates that addresses increase as we move in memory by printing the address after a certain offset.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Assignment #24: Program

The document contains 4 programming assignments involving arrays and pointers in C language. The first assignment initializes an array and assigns its elements to pointer variables to print their values. The second assignment calculates the area of a circle using a pointer to pass the result by reference. The third assignment swaps the values of two variables by passing their addresses to a function using pointers. The fourth assignment prints the address of a variable and demonstrates that addresses increase as we move in memory by printing the address after a certain offset.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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