You are on page 1of 5

EXPERIMENT NUMBER-3.

Student's name= Rojaksh Sharma


Uid = 21BCS7913
Class and group= 404-B
Semester= First

AIM OF EXPIREMENT

LEARN HOW TO USE POINTERS IN C PREREQUISITES- BASIC KNOWLEDGE OF ARRAYS AND


FUNCTIONS

ALGORITHM -
: WAP to read an array of elements and print the same in the reverse order along with their
addresses using pointer.

1. Start

2. We have declared one pointer variable and one array.

3, Address of first element of array is stored inside pointer variable.

4. Accept Size of an Array.

5.Now we have accepted element one by one using for loop and scanf statement .

6. Increment pointer variable so that it will then point to next element of array.

7. After accepting all elements store address of last element inside pointer variable.

8. Again using reverse for loop and printf statement print an array

9. End
PROGRAM CODE
#include
#include<conio.h>
#define MAX 30
void main() {
int size, i, arr[MAX];
int *ptr;
ptr = &arr[0];
printf("\nEnter the size of array : ");
scanf("%d", &size);
printf("\nEnter %d integers into array: ", size);
for (i = 0; i < size; i++) {
scanf("%d", ptr);
ptr++;
}
ptr = &arr[size - 1];

printf("\nElements of array in reverse order are :");

for (i = size - 1; i >= 0; i--) {


printf("\nElement %d is : %d ", i+1, *ptr);
ptr--;
}
}
Output

Practical 8.2: Write a function code that is returning pointer to the larger value out of two passed
values.

ALGORITHM -

1. Start
2. Declare a user defined function using pointer to store address of two variables to find
larger no. from them
3. In function definition if num1 is greater than num2 return num1 to main else return
num2 in main function .
4. In main function declare and initialize two variable and take input of these two
variable from user using scanf
5. by calling the find larger function using pointer and compare the address of two
variable given by user
6. Print the result which number is greater
7. stop

Program code :
#include <stdio.h>
int* findLarger(int*, int*);
void main()
{
int a=0;
int b=0;
int *result;

printf(" Input the first number : ");


scanf("%d", &a);
printf(" Input the second number : ");
scanf("%d", &b);

result=findLarger(&a, &b);
printf(" The number %d is larger. \n\n",*result);
}

int* findLarger(int *n1, int *n2)


{
if(*n1 > *n2)
return n1;
else
return n2;
}

OUTPUT :
LEARNING OUTCOMES

● Remember the concepts related to fundamentals of C language, draw flowcharts and


write algorithm/pseudocode.

● Understand the way of execution and debug programs in C language.

● Apply various constructs, loops, functions to solve mathematical and scientific problem.

● Analyze the dynamic behavior of memory by the use of pointers.

● Design and develop modular programs for real world problems using control structure
and selection structure.

EVALUATION COLUMN (To be filled by concerned faculty only)


Sr. No. Parameters Maximum Marks
Marks Obtained
1. Worksheet Completion including writing 10
learning objective/ Outcome
2. Post-Lab Quiz Result 5

3. Student engagement in Simulation/ 5


Performance/ Pre-Lab Questions
4. Total Marks 20

You might also like