0% found this document useful (0 votes)
26 views4 pages

Two Mark Questions - Unit 3

Uploaded by

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

Two Mark Questions - Unit 3

Uploaded by

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

TWO MARK QUESTIONS

1. What is Pointer? (Or) Define Pointer. (Or) What is the use of Pointers? (Jan 2014)
Pointer is a variable which contains the memory address of another variable.The memory
address is the location where program instructions and data are stored; pointers can be used
to access and manipulate data stored in the memory.It is always denoted by ‘*’ operator.
2. Write down the features of pointer.
 It is efficient in handling data.
 It is used for saving memory space.
 It reduces the length and complexity of the program.
 It provides dynamic memory allocation.
 Two dimensional and multidimensional array representations are easy in pointers.
3. What are the advantages of pointer?
 It is more compact and efficient code.
 It is used to achieve clarity and simplicity.
 It enables us to access the memory directly.
4. How will you declare a pointer?
Pointer is a variable that contains the address of another variable.
Syntax: data_type *pointer-name;
Eg: int *a;
5. What is & and * operator?
& - Address operator
* - Indirection Operator / Dereferencing Operator
6. What is Dereferencing Pointer?
Dereferencing Operation is performed to access or manipulate data contained in memory
location pointed to by a pointer.
Any Operation performed on the de-referenced pointer directly affects the value of variable
it points to.
7. What is indirection operator?
Asterisk (*) indirection operator is used along with pointer variable while dereferencing the
pointer variable.
Asterisk operator is also called as value at operator.
When used with pointer variable, it refers to variable being pointed to; this is called as
Dereferencing of Pointers.
8. What is the difference between the indirection and address operators? (Or) What is
an address operator and indirection operator? (Nov / Dec 2014) (Nov / Dec 2015)
The indirection operator (*) returns the value of the variable stored in a pointer.
The address operator (&) returns the memory address of the variable.
9. What does null pointer mean?
A pointer is said to be a null pointer when its right side value is 0.
A null pointer can never point to a valid data. For checking a pointer, if it is assigned to 0,
then it is a null pointer and is not valid.
10. What is a Character Pointer?
A character pointer can also be used to access character arrays and string constants in the
same way as accessing numeric arrays using their respective pointer variable.
Syntax: char *pointer_character;
11.Define Array of Pointers.
Array notation is a form of relative addressing.
The compiler treats the subscripts as a relative offset from the beginning of the array.
When a pointer variable is set to the start of an array and is incremented to find the next
element, absolute addressing is being implemented.
12. What is Pointer to Pointer?
Here one pointer stores the address of another pointer variable.
Example:
int x=10,*a,**b; a=&x;b=&a;
13. What is Dynamic Memory Allocation? (April / May 2017)
The process of allocating memory at runtime is known as dynamic memory allocation.
Library routines known as "memory management functions" are used for allocating and
freeing memory during execution of a program.
These functions are defined in stdlib.h.
14. What are the various dynamic memory allocation functions? (April / May 2017)
malloc() - Used to allocate blocks of memory in required size of bytes.
free() - Used to release previously allocated memory space.
calloc() - Used to allocate memory space for an array of elements.
realloac() - Used to modify the size of the previously allocated memory space.
15. Difference between Call by Value and Call by Reference. (Or) What is the
difference between pass by value and pass by reference? (May/June 2014)
Call by Value
Values are passed in function call.
This method copies the values of actual parameters into the formal parameters of the
function.
Here, the changes to the formal parameter do not affect the actual parameter.
Call by Reference
Address or pointers are passed in function call.
This method copies the addresses of actual parameters into the formal parameters of the
function.
Any changes to the formal parameter will affect the actual parameter.
16. How is pointer arithmetic done? (May/June 2016)
Pointers arithmetic is done by adding, subtracting, comparing, incrementing and
decrementing the values assigned to the pointer variables.
17.Define Array.
An array is a collection of similar data elements. These data elements have the same data
type. The elements of the array are stored in consecutive memory locations and are
referenced by an index also known as the subscript. Subscript is an ordinary number which
is used to identify an element of the array.
18. Define declaration of array.
Declaring an array means specifying three things
Data Type : What kind of values it can store, for example int, char, float, double
Name : To identify the array
Size : The maximum number of values that the array can hold
Arrays are declared using the following syntax:
type name[size];
19.How to calculate the address of array elements
The address of other data elements can simply be calculated using the base address. The
formula for doing this calculation is
Address of data element, A[k] =BA[A] +w(k – lower_bound)
Here, A is the array, k is the index of the element for which we have to calculate the
address, BA is the base address of the array A, w is the word size of one element in
memory (for eg, the size of int is 2), and lower_bound is the index of the first element in
the array.
20. How to calculate the length of an array.
Length of the array is given by the number of elements stored in it. The general formula to
calculate the length of the array is:
Length =upper_bound – lower_bound + 1
Where upper_bound is the index of the last element and lower_bound is the index of the
first element in the array.
21. What are the different ways of initializing array?
Elements of the array can also be initialized at the time of declaration as other variables.
When an array is initialized, we need to provide a value for every element in the array.
Arrays are initialized by writing,
type array_name[size]={list of values};
The values are written within curly brackets and every value is separated by a comma.It is
a compiler error to specify more number of values than the number of elements in the
array.
22.Given an array int a[10] ={101,102,103,104,105,106,107,108,109,110}.show the
memory representation and calcuate its length.
The array int a[10] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110} consists of 10
elements, each stored in 4 bytes. The memory representation of this array places each
element consecutively in memory, starting at a base address. Each subsequent element is
offset by 4 bytes from the previous one, with the first element at the base address, the
second at base address + 4, and so on until the last element, which is at base address + 36
bytes. The total length of the array is therefore 10.
23.why addition of two pointers is impossible?
The addition of two pointers is impossible because pointers represent specific memory
addresses, and adding two addresses together does not yield a meaningful result. In
programming, pointers are typically used for referencing memory locations, not for
arithmetic. While subtracting one pointer from another can give the difference in their
positions (useful for finding distances in arrays), adding them would not result in a valid
memory address or meaningful data location, which is why this operation is disallowed.
24. what are the advantages of using arrays?
The advantages of using arrays include:
Efficient Data Storage: Arrays allow storing multiple elements of the same data type in
contiguous memory locations, which makes accessing elements efficient.
Indexed Access: Elements in an array can be accessed using an index, allowing for direct
access to any element without traversing from the beginning.
Simplified Code: Arrays make code simpler and more readable when dealing with large
sets of data, as they allow storing data in a single variable rather than multiple variables.
Memory Efficiency: Since arrays store data contiguously, they reduce memory overhead
and make efficient use of memory.
Ease of Iteration: Arrays can be easily traversed using loops, which simplifies data
manipulation tasks such as searching, sorting, and modification.
Static Size Allocation: Arrays provide a fixed-size structure, which can prevent memory
fragmentation and improve runtime predictability in embedded systems and real-time
applications.
25. write the syntax for 2D array.
The syntax for declaring a 2D array in C is as follows:
data_type array_name[rows][columns];
data_type is the type of elements the array will hold (e.g., int, float, char).
array_name is the name of the array.
rows is the number of rows in the 2D array.
columns is the number of columns in the 2D array.
Example
int matrix[3][4];
This creates a 2D array matrix with 3 rows and 4 columns, which can hold 12 integer
values in total.

You might also like