Pr.Pg Next Pg

C Programming Interview Questions and Answers Part 10


91.What is the difference between strdup and strcpy?

  • Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc().

  • Unlike strcpy(), strdup() is not specified by ANSI.


92.What is this pointer?

  • It is a pointer that points to the current object.

  • This can be used to access the members of the current object with the help of the arrow operator.


93.What is friend function?

  • The function declaration should be preceded by the keyword friend.

  • The function definitions does not use either the keyword or the scope operator

  • The functions that are declared with the keyword friend as friend function.

  • Thus, a friend function is an ordinary function or a member of another class.


94.What is recursion?

  • A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.


95.What are the characteristics of arrays in C?

  • An array holds elements that have the same data type.

  • Array elements are stored in subsequent memory locations

  • Two-dimensional array elements are stored row by row in subsequent memory locations.

  • Array name represents the address of the starting element


96.What is the differentiate between for loop and a while loop? What are it uses?

  • For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.


97.What is the difference between printf(...) and sprintf(...)?

  • printf(....) -------------> is standard output statement

  • sprintf(......)-----------> is formatted output statement.


98.What is an explicit constructor?

  • A conversion constructor declared with the explicit keyword.

  • The compiler does not use an explicit constructor to implement an implied conversion of types.

  • Itís purpose is reserved explicitly for construction.

  • Explicit constructors are simply constructors that cannot take part in an implicit conversion.



99.What are the pointer declarations used in C?

  • 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 into

  • Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float

  • Pointer to a pointer ,e.g, int **x; Pointer to apointer to int

  • pointer to a data type ,e.g, char *p; pointer to char


100.What is the invalid pointer arithmetic?

  • adding ,multiplying and dividing two pointers.

  • Shifting or masking pointer.

  • Addition of float or double to pointer

  • Assignment of a pointer of one type to a pointer of another type

Pr.Pg border                                              Next Pg