Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 291 - 292 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 291

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the difference between the functions memmove () and memcpy () ?

Explanation

Differrence between Memmove () and Memcpy ()
memmovememcpy
Copies a specified number of bytes from one memory location to another even when there is overlapFunction is used to copy a specified number of bytes from one memory to another.
Overlap can happen on memmove () .Overlapping memory cannot be used in memcpy () .
It should not be done in non-destructive way.It should be done in non-destructive way.

Question 292

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     char ⚹p =“GOOD” ;
  4.     chara[ ] =“GOOD” ;
  5.     printf ( “sizeof (p) =%d, sizeof ( ⚹p) =%d, strlen (p) =%d” sizeof (p), sizeof ( ⚹p), strlen (p) );
  6.     printf ( “sizeof (a) =%d, strlen (a) =%d” ,sizeof (a), strlen (a) );
  7. }

Explanation

Size of (p) = 2, size of (⚹ p) = 1, strlen (p) = 4 size of (a) = 5, strlen (a) = 4

In the program

Table Shows the Program
char ⚹ p = “GOOD” ;
  • Given the character pointer p = “GOOD”
char a [] = “GOOD” ;
  • Given the character array a
printf ( “sizeof (p) =% d, sizeof (⚹ p) =% d, strlen (p) =% d” sizeof (p) , sizeof (⚹ p) , strlen (p) ) ;
  • Here sizeof (p) ⩾ sizeof (char ⚹) ⩾ 2

    sizeof (⚹ p) ⩾ sizeof (char) ⩾ 1

  • When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable
printf ( “sizeof (a) =% d, strlen (a) =% d” , sizeof (a) , strlen (a) ) ;
  • sizeof (a) ⩾ size of the character array ⩾ 5
  • here the sizeof (a) where a is the character array and the size of the array is 5
  • because the space necessary for the terminating NULL character should also be taken into account

Developed by: