115. Differentiate Between Pointers & Arrays With Example?
Answer: Pointers and arrays are very closely linked in C. Consider the following statements:
int a[10], x;
int *ptr; /* ptr is a pointer variable*/
ptr = &a[0]; /* ptr points to address of a[0] */
x = *ptr;
/* x = contents of ptr (a[0] in this case) */
A pointer is a variable so we can do ptr = a and ptr++ ; while an array is not a variable so statements a = pa and a++ are illegal.
116. What Is The Size Of int Pointer, Float Pointer & Char Pointer In C In 32-bit Compiler & 64 bit Compiler?
Answer: In a 32 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 4 bytes and for 64 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 8 bytes
117. Difference Between An Array Name & A Pointer Variable?
Answer: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value , ++ and -- operators cannot be applied to it.
118. Difference Between An Array Of Pointers & A Pointer To An Array?
Answer: Differences between the two are: Array of pointers:
- Declaration of Array Of Pointers: data_type *array_name[size]; whereas Declaration of Pointer To An Array data_type ( *array_name)[size];
- Size represents the row size in case of Array Of Pointers whereas Size represents the column size in case of Pointer To An Array.
119. What Are The Pointer Declarations Used In C?
Answer:
Array of pointers, e.g , int *a[10]; Array of pointers to integer
Pointers to an array,e.g , int (*a)[10]; Pointer to an array of int
Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float
Pointer to a pointer ,e.g, int **x; Pointer to a pointer to int
Pointer to a data type ,e.g, char *p; Pointer to char
120. Differentiate Between A Constant Pointer & Pointer To A Constant?
Answer:
const char *p; // pointer to a const character.
char const *p; // pointer to a const character.
char * const p; // const pointer to a char variable.
const char * const p; // const pointer to a const character.
121. What Is The Invalid Pointer Arithmetic?
Answer: Invalid Pointer arithmetic are:
- Adding, multiplying and dividing two pointers are not allowed.
- Shifting or masking pointer.
- Addition of float or double to pointer.
- Assignment of a pointer of one type to a pointer of another type.
122. What Are The Advantages Of Using Array Of Pointers To String Instead Of An Array Of Strings?
Answer: Some of the advantages of using array of pointers to string over an array of strings are:
- Efficient use of memory.
- Easier to exchange the strings by moving their pointers while sorting.
123. Are The Expressions *ptr ++ & ++ *ptr Same?
Answer: No,*ptr ++ increments pointer and not the value pointed by it. Whereas ++ *ptr increments the value being pointed to by ptr.
124. Explain The Declaration int (*p (char *a))[10].
Answer: int (*p (char *a))[10];
interpretation of the above statement is:
int (*p (char *a))[10];
char *a :- pointer to character (Character Array)
(*p (Character Array))
int (*p (Character Array))
Integer pointer to character array
int (*p (Character Array))[10]
Array of integer pointer to character array
The given statement represent array of int pointer to char array.
125. What Is Increment Factor Term Used In Pointers?
Answer: While incrementing a pointer, its value gets increased by the length of the data type to which it points. This length is called increment factor.
126. When Are char[] & char * Treated As Same By The Compiler?
Answer: When using them as formal parameters while defining a function.
127. To free() We Only Pass The Pointer To The Block Of Memory Which We Want To Deallocate. Then How Does free() Know How Many Bytes It Should Deallocate?
Answer: In most implementations of malloc() the number of bytes allocated is stored adjacent to the allocated block. Hence it is simple for free() to know how many bytes to deallocate.
128. What Is A Far Pointer In C?
Answer: A far pointer in C refers to a pointer which is capable of pointing or accessing the whole of RAM’s residence memory. The far pointer can access all 16 segments of the residence memory.
128. What Are The Difference Between A Null Pointer, A Null Macro, The ASCII NUL Character & A Null String?
Answer: Differences between a null pointer, null macro and ascii null character, and a null string are:
- A null pointer is a pointer which does not point anywhere.
- A null macro is used to represent the null pointer in source code. It has a value 0 associated with it.
- The ASCII Null character has all its bits as 0 but does not have any relation with null pointer.
- The null string is just another name for an empty string "".
Also Read The Following Questions:
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?
61) What is static memory allocation?
62) What is dynamic memory allocation?
63) What is the purpose of realloc?
64) What is pointer to a pointer?
65) What is an array of pointers?
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?
...Return To C Questions INDEX.
...Return To C Programming INDEX.
... Return To HR Interview Index
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com