Languages [3i Infotech Placement]: Sample Questions 39 - 39 of 546

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

Question 39

Edit

Describe in Detail

Essay▾

Find the output for the following C program

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     char ⚹p1;
  5.     char ⚹p2;
  6.     p1 =(char ⚹) malloc (25);
  7.     p2 =(char ⚹) malloc (25);
  8.     strcpy (p1, “Ramco” );
  9.     strcpy (p2, “Systems” );
  10.     strcat (p1, p2);
  11.     printf ( “%s”, p1);
  12. }

Explanation

  • In the program
Table Showing the Program
char ⚹ p1;
  • Define the character pointer p1
char ⚹ p2;
  • Define the character pointer p2
p1 = (char ⚹) malloc (25) ;
  • Pointer p1 using malloc function
  • Malloc () allocates the requested memory and returns a pointer to it.
p2 = (char ⚹) malloc (25) ;
  • Pointer p2 using malloc function
strcpy (p1, “Ramco” ) ;
  • strcpy () function- char ⚹ strcpy (char ⚹ dest, const char ⚹ str) copies the string pointed to by src to dest
Dest-this is the pointer to the destination array where the content is to be copied.

Src-this is the string to be copied.

  • strcpy (p1, “Ramco” ) here p1 is dest and “Ramco” is src
strcpy (p2, “Systems” ) ;
  • strcpy (p2, “Systems” ) here p2 is dest and “Systems” is src
strcat (p1, p2) ;
  • char ⚹ strcat (char ⚹ dest, const char ⚹ src) appends the string pointed to by src to the end of the string pointed to by dest.
printf ( “% s” , p1) ;
  • printf prints “RamcoSystems”

Developed by: