C Language Interview Question and Answers
36. |
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. |
|
|
37. |
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 . |
|
|
38. |
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. |
|
Anjali, said |
Mar 08, 2014 |
Both are same but char* const p is different as here the pointer's value can not be changed but the char's value can be changed.
|
|
39. |
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.
|
|
|
40. |
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. |
|
|