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

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     charp[ ] =“%d”;
  4.     p[1] =‘c’;
  5.     printf (p, 65);
  6. }

Explanation

In the program

Table Shows the Program
p [1] = ‘c’ ;
  • Due to the assignment p [1] = ‘c’ the string becomes, “% c” .
printf (p, 65) ;
  • Since this string becomes the format string for printf and ASCII value of 65 is ‘A’ , the same gets printed.

Question 152

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     char ⚹p;
  4.     p =“%d”;
  5.     p ++;
  6.     p ++;
  7.     printf (p − 2, 300);
  8. }

Explanation

In the program

Table Shows the Program
char ⚹ p;Declare character pointer p
p = “% d” ;Pointer p points to ‘% d’
p ++ ;

p ++ ;

It is incremented twice
printf (p − 2,300) ;Decremented by 2, it points to ‘% d’ and 300 is printed.

Question 153

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     charstring[] =“HelloWorld” ;
  4.     display (string);
  5. }
  6. voiddisplay (char ⚹string)
  7. {
  8.     printf ( “%s” string);
  9. }

Explanation

  • In a program third line, when the function display is encountered
  • The compiler doesn՚t know anything about the function display
    Table Shows the Program
    display (string) ;In a function we assumes the arguments and return types to be integers (which is default type)
  • When it sees the actual function display, the arguments and type contradicts with what it has assumed previously
  • Hence compile time error occurred.

Developed by: