C Programming Interview Questions With Answers - Part XIII.
104. What Is A Near Pointer?
Answer: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64KB segment.
105. How Many Bytes Are Occupied By Near, Far & Huge Pointers?
Answer: The near pointer is 2 bytes long and far and huge pointers are 4 bytes long.
106. What Are Dangling Pointers?
Answer: Dangling pointer is a concept which results when you have a pointer pointing to a location in memory that is meaningless. For example, consider the function
void DanglingPointer(int *x)
x = &y;
When the function is called, space is allocated for the variable y on the stack, and the pointer x contains the address of that space. But when the function returns control to the calling function, the space that was allocated for y is cleared and x points to a meaningless location in memory
107. What Is A NULL Pointer? Whether It Is Same As An Uninitialized Pointer? What Does The Error ‘Null Pointer Assignment’ Means & What Causes This Error?
Answer: Null pointer is a pointer which points to nothing but uninitialized pointer may point to anywhere.
As null pointer points to nothing so accessing an uninitialized pointer or invalid location may cause an error.
108. Are Pointers Integer?
Answer: No, pointers are not integers. A pointer is an address. It is a positive number.
109. What Is Generic Pointer In C?
Answer: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer, conversions are applied automatically (implicit conversion).
110. How Pointer Variables Are Initialized?
Answer: Pointer variables are initialized by one of the following ways.
- Static memory allocation.
- Dynamic memory allocation.
111. What Is Pointer To A Pointer?
Answer: If a pointer variable points another pointer value. Such a situation is known as a pointer to a pointer. Example:
Here p2 is a pointer to a pointer.
112. What Is An Array Of Pointers?
Answer: If the elements of an array are addresses, such an array is called an array of pointers.
113. Difference Between Array & Pointer?
Answer: Differences between array and pointers are:
- Array allocates space automatically whereas pointer is explicitly assigned to point to an allocated space.
- Arrays cannot be re-sized whereas pointers can be sized using realloc().
- Arrays cannot be reassigned whereas Pointer can be reassigned.
- sizeof (array name) gives the number of bytes occupied by the array whereas Sizeof (p) returns the number of bytes used to store the pointer variable p.
114. What Are References. State The Differences Between Reference & Pointer.
Answer: Like a pointer, a reference is an alias for an object (or variable), is usually implemented to hold a machine address of an object (or variable), and does not impose performance overhead compared to pointers.
The notation X& means "reference to X".
Differences between reference and pointer are:
- A reference can be accessed with exactly the same syntax as the name of an object.
- A reference always refers to the object to which it was initialized.
- There is no “null reference”, and we may assume that a reference refers to an object.
Two things to note on references:
- One cannot have a pointer to a reference.
- One cannot define an array of references.
Also Read The Following Questions:
66) Difference between array and pointer?
67) Difference between a array name and a pointer variable?
68) Difference between an array of pointers and a pointer to an array?
69) What are the pointer declarations used in C?
70) Differentiate between a constant pointer and pointer to a constant?
71) What is the invalid pointer arithmetic?
72) What are the advantages of using array of pointers to string instead of an array of strings?
73) Are the expressions *ptr ++ and ++ *ptr same?
...Return To C Questions INDEX.
...Return To C Programming INDEX.
... Return To HR Interview Index