Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 15 - 16 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 15

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Find the output for the following C program

  1. main ()
  2. {
  3.     char ⚹ptr =“RamcoSystems”;
  4.     ptr ++;
  5.     printf ( “%s”, ptr);
  6.     ptr++;
  7.     printf ( “%s”, ptr);
  8. }

Explanation

  • In the program
Table Showing the Program
char ⚹ ptr = “Ramco Systems” ;
  • define the character pointer ptr = “Ramco Systems”
⚹ ptr ++ ;
  • Increment the pointer ptr value
printf ( “% s” , ptr) ;
  • printf prints the ptr value
  • ptr thus points to “amco Systems”
ptr ++ ;
  • ptr value is amco Systems than increment the ptr values
  • Now ptr value is “mco Systems”
printf ( “% s” , ptr) ;
  • printf prints the ptr value
  • ptr now is “mco Systems”

Question 16

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     char ⚹str1 =“abcd” ;
  4.     charstr2[] =“abcd”;
  5.     printf ( “%d %d %d” sizeof (str1), sizeof (str2), sizeof ( “abcd” ) );
  6. }

Explanation

In a program,

Table Shows the Program
char ⚹ str1 = “abcd” ;Given the character pointer
char str2 [] = “abcd” ;Given the name of the array
printf ( “% d % d % d” sizeof (str1) , sizeof (str2) , sizeof ( “abcd” ) ) ;
  • In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable.
  • In second sizeof the namestr2 indicates the name of the array whose size is 5 (including the ‘⧵0’ termination character) .
  • The third sizeof is similar to the second one.

Developed by: