Skip to main content

C Programming Interview Questions With Answers - Part XIV.


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

Popular posts from this blog

Tell Me Something About Yourself - Interview Answers.

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview . That's why this statement is often called the "Positioning Statement". One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly. YOUR ANSWERS CAN BE: 1) I am a person with strong interpersonal skills and have the ability to get along well with people . I enjoy challenges and looking for creative solutions to problems. 2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies apti...

HR Interview Questions With Simple Answers - Top 30.

Here are some very important HR questions which are often asked during Interviews and I believe these answers can really help you to get through....... Click on them to view the answer: 1) Tell Me Something About Yourself ? 2) What Are Your Strengths? 3) What Are Your Weaknesses? 4) How Do You Handle Pressure / Can You Work Well Under Pressure? 5) What Are Your Short Term Goals? 6) What Are Your Long Term Goals? 7) Where Do You See After 5 Years? 8) Why Should We Hire You? 9) What Is Your Salary Expectation? 10) Why Do You Want To Leave Your Current Job? 11) Do You Prefer To Work Alone Or As A Team Player? 12) What Made You Choose Your Major / Stream? 13) Why Didn’t You Pursue A Career In Your Major / Stream? 14) Why Do You Want To Work For Us? 15) Are You Willing To Travel? 16) Are You Willing To Take Risks? 17) What Do You Know About This Company? 18) What Do You Seek From A Job? 19) How Do You Evaluate Success? 20) Dur...

Sample Cover Letter / Job Application.

To The General Manager (HR) [ Name and Designation (Bold Words)] Infosys Limited Delhi – 110001 Uttam Agrawal Gandhi Chowk, Bhartee Street [ Name Bhawanipatna, Kalahandi Contact Address Orissa – 766001 Telephone No.] Ph. no - +91-9438170446 [Sub: Application for the position of ___________ in your esteemed organization.] Respected Sir, (Always use ‘Respected’) With reference to your advertisement dated 14th may’ 08 in The Times of India for the position of ___________ . I would like to place myself as a strong contender before you. OR This has reference to your advertisement dated 14th may’ 08 in The Times of India for the position of ____________. In the said connection I take this opportunity to apply for the said position as a strong contender. /*This is the Introduction i.e the first paragraph of your application/* ( Now the Second Paragraph is the Self Introduction) Try to start the second paragraph with the below mentioned lines: - I have the p...