Cpp Practical File
Cpp Practical File
INDEX
No. Practical Question Date Teacher’s
Sign
OBJECTS: When a class is defined, only the specification for the object
is defined; no memory or storage is allocated. To use the data and
access functions defined in the class, you need to create objects.
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
Both references and pointers can be used to change the local variables of
one function inside another function. Both of them can also be used to
save copying of big objects when passed as arguments to functions or
returned from functions, to get efficiency gain.
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
In C++, dynamic memory allocation allows us to allocate memory during runtime. Dynamic
allocation in an array is particularly useful when the size of an array is not known at compile
time and needs to be specified during runtime.
In C++, we use the new operator for dynamic memory allocation .
NEW OPERATOR :
The new operator denotes a request for memory allocation on the Free Store. If sufficient
memory is available, a new operator initializes the memory and returns the address of the
newly allocated and initialized memory to the pointer variable.
Syntax to use new operator
pointer-variable = new data-type;
DELETE OPERATOR :
Since it is the programmer’s responsibility to deallocate dynamically allocated memory,
programmers are provided delete operator in C++ language.
Syntax:
Release memory pointed by pointer-variable
delete pointer-variable;
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
PRACTICAL 19:
Write a Programm to show dynamic memory allocation using array
MSI JANHVI 2023-2026
Output:
PRACTICAL 20:
WAP to store data of 50 employees using arrays and arrays of object.
MSI JANHVI 2023-2026
Practical 21: Write a program showing “this pointer” with suitable example.
MSI JANHVI 2023-2026
OUTPUT:
OUTPUT:
PRACTICAL 23:
MSI JANHVI 2023-2026
JANHVI
JANHVI
OUTPUT :
JANHVI
JANHVI
OUTPUT :
MSI JANHVI 2023-2026
OUTPUT:
OUTPUT:
MSI JANHVI 2023-2026
OUTPUT:
OUTPUT :
PRACTICAL 34: Write a program to illustrate the use of try, catch and
throw statements.
MSI JANHVI 2023-2026
OUTPUT:
OUTPUT :
OUTPUT:
MSI JANHVI 2023-2026
OUTPUT: