C Programming Question and Answers

77. What is the difference between memcpy() & strcpy() functions in C?
  memcpy() function is used to copy a specified number of bytes from one memory to another. Whereas, strcpy() function is used to copy the contents of one string into another string.
memcpy() function acts on a memory rather than value. Whereas, strcpy() function acts on value rather than memory.
 
Your Name Your Email-ID
Your Answer
78. What are binary trees?
  Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and right one. Each side can further branch to form additional nodes, which each node having two pointers as well.
 
Your Name Your Email-ID
Your Answer
79. What is stack memory allocation and dynamic memory allocation?
 
  • The compiler allocates the required memory space for a declared variable. By using the address of a operator, the reserved address is obtained and this address may be assigned to a pointer variable. Since, most of the declared variable has static memory, this way of assigning pointer value to a pointer variable is known as static memory allocation. Memory is assigned during compilation time.
  • Dynamic memory allocation: it uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these functions are assigned to pointer variables, such assignments are known as dynamic memory allocation. Memory is assigned during run time.
 
Your Name Your Email-ID
Your Answer
80. What is the difference between calloc and malloc?
  calloc and malloc are used for dynamic memory allocation. calloc initializes the memory locations to zero by default but malloc memory contains garbage values.
 
Your Name Your Email-ID
Your Answer