You are on page 1of 3

Lab 01: Primitive Data Types, Custom Data Types, Pointers

Objective:

The objective of this lab is to implement the declaration, initialization, values assignment, and values
output for primitive and custom data types.

Scope:

This lab focuses on two categories of data types i. Primitive Types (bool, char, int, long, float, double) ii.
Custom Types. Students will be taught the declaration, initialization, data assignment and retrieval from
the variables of these categories. The use of the pointers to access and manipulate the data values will
also be taught to students.

Task 01:

Write a C++ program to declare one variable each of types i. char ii. int iii. float iv. double. Initialize the
declared variables with constant values and output the values of the declared variables using cout
statement.

Objective:

Declaring, initializing and accessing the primitive values.

Solution:

Will be shared later.

Task 02:

Write a C++ program to declare one array of size 5 for each of the following types:

i. char
ii. int
iii. float
iv. double.

Initialize the declared arrays with constant values and output the values of the declared variables using
cout statement.

Note: Use for-loop the iterate over the elements of the array declared during this example.

Objective:

Declaring, initializing and accessing the arrays containing primitive values.

Solution:

Will be shared later.


Task 03:

Write a C++ program to:

1. Declare one array (of size 5) for each of types


i. int
ii. char
iii. float
iv. double

2. Initialize the declared arrays with appropriate values.


3. Declare one pointer each for every array declared above
4. Assign starting address of each array to the appropriate pointer variable
5. Iterate over each of the elements for arrays declared above using for-loop
6. Output the values of the all array elements using pointers (without using array-name)

Objective:

Declaring the primitive arrays, initializing and output variables using pointers.

Solution:

Will be shared later.

Task 04:

Write a C++ program to:

1. Declare one variable each of types


v. Int
vi. char
vii. float
viii. double

2. Initialize the declared variables with appropriate values.


3. Declare the pointers for each of above variables.
4. Assign the addresses of above variables using appropriate pointer variables.
5. Output the values of the declared variables indirectly (through pointers) using cout statement.

Objective:

Declaring the primitive type variables, initializing and output variables using pointers.

Solution:

Will be shared later.


Exercises:

1. Write a program that finds a given number from an array. The elements in the array would be
entered by the user.
2. Write a program that performs the summation of diagonal elements of a matrix of N*N order.
3. Write a program that finds minimum and maximum number from an array and display number and
its memory address
4. Write a program that initializes an integer array of size N with positive values. The program operates
over the array data and outputs the prime numbers from the array.

You might also like