0% found this document useful (0 votes)
7 views

Lab#01 Task

The document describes three lab activities about pointers and arrays in C/C++. The first activity involves declaring a pointer to reference an array, displaying elements, and finding the maximum value. The second activity uses pointers to write functions for finding the smallest value in an array and traversing an array from last to first index. The third activity sorts a dynamic array by passing it to a sorting function.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lab#01 Task

The document describes three lab activities about pointers and arrays in C/C++. The first activity involves declaring a pointer to reference an array, displaying elements, and finding the maximum value. The second activity uses pointers to write functions for finding the smallest value in an array and traversing an array from last to first index. The third activity sorts a dynamic array by passing it to a sorting function.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Instructor: Engr.

Amna Arooj Lab No: 01 Dated: 14/09/2023

Lab Activity 1:

Learning objective: How to access and operate arrays through pointers


In C/C++ language, arrays work on memory addresses so as pointers and hence they are
strongly related. Design a C program which take an array of 6 elements from the user and do
the following:
a) Declare the pointer and refernce it with the array address
b) Display every element of an array by using the pointer
c) Find the maximum value in array using pointer

Lab Activity 2:
Learning Objective: Pointers in function call
In this activity you will have to use pointers to perform the following tasks on randomly
generated 1D array of type int having size of 20.
i. Write a function int smallest = smallest_value(int *temp, int size), which receives
an array as pointer and find out smallest value using pointer to array.
ii. Write a function void traversal_back(int *temp, int sizeofarry), which receives an
array as pointer and traverse array from last index to first index and print its value
with its address as well.
Lab Activity 3:
Learning Objectives: Operations on dynamic arrays
When we pass pointers to some function, the addresses of actual arguments in the calling
function are copied into the arguments of the called function.
Design a C program in which we declare a dynamic array of n elements and initialize it with
some random values. You have to sort all the array elements in ascending order by sending the
array to a user defined function i.e. SORTING. The prototype for the function SORTING is as
under:
Void sorting (int * ,int );
Display the unsorted and sorted array as a result.
Hint: you may build more than one functions to complete the task
Expected Output:

You might also like