This document summarizes an experiment on using pointers in C programming. The aim was to use pointers to print an array in reverse order along with the addresses of each element. The student defined two programs - Program A prints the reverse of an integer array using pointers, while Program B defines a function to return the pointer to the maximum of two integers. The student encountered no errors, explained the programs, and listed the learning outcomes regarding C language fundamentals and using pointers to manipulate memory.
Software and Systems Engineering Standards: Verification and Validation of Sy...
Pointer Experiment Report
1. SUBJECT NAME-Fundamentalsof ComputerProgramming SUBJECT CODE-21CSH101
STUDENT’S NAME –Ankita Sharma
STUDENT’S UID – 21BCS2219
CLASS AND GROUP –13A
SEMESTER –1
EXPERIMENT NUMBER – 3.1
AIM OF THE EXPERIMENT– To LEARN HOW TO USE POINTERS
IN C
A) WAP to read an array of elements and print the same in the reverse
order along with their addresses using pointer.
B)WAP to read an array of elements and print the same in the reverse
order along with their addresses using pointer.
FLOWCHART/ALGORITHM-
A)
STEP 1: START
o STEP 2: INITIALIZE arr[] = { }
o STEP 3: length= sizeof(arr)/sizeof(arr[0])
o STEP 4: PRINT "Original Array:"
o STEP 5: REPEAT STEP 6 and STEP 7 UNTIL i<length
o STEP 6: PRINT arr[i]
o STEP 7: i=i+1
o STEP 8: PRINT new line.
o STEP 9: PRINT "Array in reverse order"
o STEP 10: SET i=length-1. REPEAT STEP 11 and STEP 12 UNTIL i>=0
o STEP 11: PRINT a[i]
o STEP 12: i=i-1
o STEP 13: RETURN 0.
o STEP 14: END
B)
2. SUBJECT NAME-Fundamentalsof ComputerProgramming SUBJECT CODE-21CSH101
Step 1: START
Step 2: declare a function
Step 3: declare integer variables
Step 4: enter two comparable values
Step 5: then enter pointer variables to store the values
Step 6: then define the function
Step 7: if the value pointed by pointer m is greater than it return the address
stored in pointer n
Step 8: else it will return the address stored in pointer n
Step 9: end
PROGRAM CODE
#include <stdio.h>
int main()
{
int n, i, arr1[15];
int *pt;
printf("nn Pointer : Print the elements of an array in reverse order :n");
printf(" Input the number of elements to store in the array (max 15) :n
");
scanf("%d",&n);
pt = &arr1[0];
printf(" Input %d number of elements in the array : n",n);
for(i=0;i<n;i++)
{
printf(" element - %d : ",i+1);
scanf("%d",pt);
pt++;
}
pt = &arr1[n - 1];
printf("n The elements of array in reverse order are :");
for (i = n; i > 0; i--)
{
printf("n element - %d : %d ", i, *pt);
pt--;
}
printf("nn");
3. SUBJECT NAME-Fundamentalsof ComputerProgramming SUBJECT CODE-21CSH101
return 0;
}
B)
#include <stdio.h>
int *getMax(int *, int *);
int main(void) {
int x, y;
printf(" FIND MAX VALUEn Enter two integers-n ");
scanf("%d%d", &x,&y);
int *max = NULL;
max = getMax(&x, &y);
printf(" Max value: %dn", *max);
return 0;
}
int *getMax(int *m, int *n) {
if (*m > *n) {
return m;
}
else {
return n;
}
}
ERRORS ENCOUNTERED DURING PROGRAM’S
EXECUTION
(Kindly jot down the compile time errors encountered)
No errors encountered.
4. SUBJECT NAME-Fundamentalsof ComputerProgramming SUBJECT CODE-21CSH101
PROGRAMS’ EXPLANATION (in brief)
In program(A), we need to print the elements of the array in reverse order
that is; the last element should be displayed first, followed by second last
element and so on.
B)
Since the name of an array is a pointer to the 0th element of the array. Here
we are passing two arguments to the function return_pointer(). The arr is
passed using call by reference (notice that name of the array is not preceded
by & operator because the name of the array is a constant pointer to the 0th
element of the 1-D array) and i is passed using call by value. Inside the
function pointer p is incremented by n and reassigned to p. Finally, the
pointer p is returned to the main() function and reassigned to ptr.
Never return a pointer to local variable from a function.
OUTPUT
6. SUBJECT NAME-Fundamentalsof ComputerProgramming SUBJECT CODE-21CSH101
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
learning objective/ Outcome
10
2. Post-Lab Quiz Result 5
3. Student engagement in Simulation/
Performance/ Pre-Lab Questions
5
4. Total Marks 20