Pr.Pg Next Pg

C Programming Interview Questions and Answers Part 9

 

81.What is copy constructor?

  • Copy constructor is a constructor function with the same name as the class and used to make deep copy of objects.

 

82.What is the difference between #include‹ › and #include “ ”?

  • #include‹ › ----> Specifically used for built in header files.

  • #include “ ” ----> Specifically used for used for user defined/created n header file.

 

83.What are the features of C Langauges?

  • In C one can write programs like that of high level languages as in COBOL, BASIC, FORTRAN etc. as well as it permits very close interaction with the inner workings of the computer.

  • It is a general purpose programming language.

  • It is usually called system programming language but equally suited to writing a variety of applications.

  • It supports various data types

  • It follows the programming style based on fundamental control flow constructions for structured programming

  • Functions may be pre–defined or user defined and they may return values of basic types, structures, unions or pointers.

 

 

84.What is the difference between a string copy (strcpy) and a memory copy (memcpy)?

  • The strcpy() function is designed to work exclusively with strings.

  • It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved.

  • On the other hand, the memcpy() function is designed to work with any type of data.

  • Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination.

 

85.What is the difference between a NULL Pointer and a NULL Macro?

  • Null pointer is a pointer that is pointing nothing while NULL macro will used for replacing 0 in program as #define NULL 0 .

 

86.What is the difference between const char*p and char const* p?

  • const char*p - p is pointer to the constant character. i.e value in that address location is constant.

  • const char* const p - p is the constant pointer which points to the constant string, both value and address are constants.

 

87.What is the purpose of realloc()?

  • Realloc(ptr,n) function uses two arguments.

  • The first argument ptr is a pointer to a block of memory for which the size is to be altered.

  • The second argument n specifies the new size.The size may be increased or decreased.

 

88.What is a pointer value and address?

  • A pointer value is a data object that refers to a memory location.

  • Each memory location is numbered in the memory.

  • The number attached to a memory location is called the address of the location.

 

89.What is the use of typedef?

  • The typedef help in easier modification when the programs are ported to another machine.

  • A descriptive new name given to the existing data type may be easier to understand the code.

 

90.What are the differences between new and malloc?

  • new initializes the allocated memory by calling the constructor.

  • Memory allocated with new should be released with delete.

  • malloc allocates uninitialized memory.

  • The allocated memory has to be released with free. new automatically calls the constructor while malloc(dosen’t)

Pr.Pg border                                              Next Pg