Unit-4 Run Time Env.
Unit-4 Run Time Env.
UNIT- 4 - RUN-TIME
TIME ENVIRONMENTS
Q- What is procedure
Dynamic memory allocation refers to the process of allocating memory for a program or application during runtime.
In contrast to static memory allocation, which happens during compilation time, dynamic memory allocation allows
a program to use memory as needed while the program is running.
Dynamic memory allocation involves using functions such as malloc() or new to request a block of memory from the
operating system, and then using the returned pointer to access and manipulate the memory. The size of the block
can be specified by the programmer at the time of the request, and the allocated memory can be resized or freed as
needed using functions such as realloc() or delete.
Dynamic memory allocation is commonly used in programming languages like C, C++, and Java to create data
structures such as linked lists, trees, and arrays that can grow or shrink in size as needed during program execution.
However, improper use of dynamic memory allocation can lead to memory leaks, buffer overflows, and other
memory-related errors.
Parameter passing is the process of passing values or references of arguments to a function during
its call. There are several techniques for parameter passing in C, including pass-by-value, pass-
by-reference, and pass-by-pointer.
Call-by-value: In Call-by-value, the value of the argument is copied into the parameter of the
function. Any changes made to the parameter within the function do not affect the original
argument.
Example:
#include <stdio.h>
void square(int num) {
num = num*num ;
printf("Square of the number is %d\n", num);
}
int main()
{
Int n=5;
Square (n);
//passing 'n' by value
Print("Original number is %d\n",n);
Return0 ;
}
In the above example, the value of n is passed to the function square() by value. The function
calculates the square of the number and prints it. However, the original value of n remains
unchanged, as it was not modified within the function. The output of the program would be:
Square of a number is 25
Original number is 5