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

Unit-4 Run Time Env.

This document contains questions and answers related to run-time environments and compiler design concepts. It discusses the definition of a symbol table, the common entries it contains like name, type, scope, value, and size. It also explains dynamic memory allocation, which allows programs to request and manage memory during runtime using functions like malloc() and delete. Finally, it describes different parameter passing techniques in C like call-by-value, call-by-reference, and call-by-pointer, and provides examples to illustrate how each technique works.

Uploaded by

Pulkit Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Unit-4 Run Time Env.

This document contains questions and answers related to run-time environments and compiler design concepts. It discusses the definition of a symbol table, the common entries it contains like name, type, scope, value, and size. It also explains dynamic memory allocation, which allows programs to request and manage memory during runtime using functions like malloc() and delete. Finally, it describes different parameter passing techniques in C like call-by-value, call-by-reference, and call-by-pointer, and provides examples to illustrate how each technique works.

Uploaded by

Pulkit Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIT- 4 - RUN-TIME ENVIRONMENTS

UNIT- 4 - RUN-TIME
TIME ENVIRONMENTS

Q- What is procedure

Q - Define Activation Tree

Q- What is Control Stack


Q- Explain Storage Organization
ation
Q- Define Activation Records.
Q- Explain Various Storage Allocation Strategies.
Q What is symbol table. Name the entries in symbol table.
In compiler design, a symbol table is a data structure used by compilers to keep track of
information about the variables, functions, and other identifiers used in a program. It is
essentially a table or a hash table that stores information about each identifier that appears in the
source code, such as its name, type, scope, and memory location.
The symbol table can be thought of as a mapping between identifier names and their attributes,
which are stored in the table entries. Here are some common entries that can be put in a symbol
table:
1 Name: the identifier's name
2 Type: the identifier's data type (integer, float, string, etc.)
3 Scope: the region of the program where the identifier is visible and accessible (global, local,
5 Value: the initial value or current value of the identifier
6 Size: the size of the identifier in memory (in bytes)
7 Nesting level: the level of nesting of the block in which the identifier is declared
8 Function arguments: the number and types of arguments expected by a function
9 Attribute flags: additional attributes that may be associated with an identifier, such as whether it
is constant, static, or volatile.
The symbol table is an essential component of a compiler, as it allows the compiler to perform
various checks and optimizations, such as type checking, scope resolution, and code generation.

Q- What do you mean by dynamic memory allocation

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.

Q- What is parameter Passing Techniques explain.

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

Call -by-reference: In Call-by-reference, a reference (or a pointer) to the argument is passed to


the parameter of the function. Any changes made to the parameter within the function affect the
original argument.
Example:
#include <stdio.h>
void square_ref(int *num)
*num = (*num) * (*num);
printf("Square of the number is %d\n", *num);
}
int main() {
int n = 5;
square_ref(&n); // passing 'n' by reference
printf("Original number is %d\n", n);
return 0;
In the above example, a reference to n is passed to the function square_ref() using the
address-of operator &. The function calculates the square of the number and modifies the original
value of n. The output of the program would be:
Square of the number is 25 Original number is 25
Call-by-pointer: Call-by-pointer is similar to pass-by-reference, except that the function
parameter is a pointer to the argument.
Example:
# } #include <stdio.h>
void square_ptr(int *num_ptr) {
*num_ptr = (*num_ptr) * (*num_ptr);
printf("Square of the number is %d\n", *num_ptr);
}
int main() {
int n = 5;
int *n_ptr = &n;
square_ptr(n_ptr); // passing 'n' by pointer
printf("Original number is %d\n", n);
return 0;
}
In the above example, a pointer to n is passed to the function square_ptr(). The function
calculates the square of the number and modifies the original value of n. The output of the
program would be the same as in the call-by-reference example:

Square of the number is 25 Original number is 25

You might also like