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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     externi;
  4.     printf ( “%d”, i);
  5.     {
  6.         inti =20;
  7.         printf ( “%d”, i);
  8.     }
  9. }

Explanation

In the program

Table Shows the Program
extern i;
  • Declare extern variable i
  • The extern keyword means “declare without defining” .
  • This means that the object or function is accessible through this name from other translation units in the program.
printf ( “% d” , i) ;
  • The identifier i is available in the inner block and so using extern has no use in resolving it.

Question 289

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is a parameterized type?

Explanation

  • A template is a parameterized construct or type containing generic code that can manipulate any type.
  • Called parameterized because actual type is a parameter of the code body.
  • Polymorphism achieved through parameterized types is called parametric polymorphism.
  • Parametric polymorphism allows same code to be used on different types passed as parameters.
Given the Image is Parameterized Type (Polymorphism)

Question 290

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     unsignedinti;
  4.     for (i =1; i>-2; i--)
  5.     printf ( “captitude” );
  6. }

Explanation

In the program

Table Shows the Program
unsigned int i;Here i is an unsigned integer.
for (i = 1; i >-2; i-)i is compared with a signed value.

Since the both types does not match, signed is promoted to unsigned value.

The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop

Difference between Signed and Unsigned Int Data Type

Developed by: