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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

1. voidmain ()
2. {
3.     staticinti;
4.     while (i<=10)
5.     (i>2)? i ++:i--;
6.     printf (“%d”, i);
7. }

Explanation

In the program

 static int i; Since i is static.It is initialized to 0. while (i <= 10)(i > 2) ? i ++ : i-; Inside the while loop the conditional operator evaluates to false, executing i-This continues till the integer value rotates to positive value (32767) . printf ( “% d” , i) ; The while condition becomes false and hence, comes out of the while loop, printing the i value.

Question 109

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is polymorphism? Explain with an example?

Explanation

A single function which is used for different purpose depending upon the parameters passes is a polymorphic function

Example:

• Area is the function name which is used for calculating areas of the rectangle, triangle, and even more.
• area (a) ; ◊ area of the square
• area (l, b) ; ◊ area of the rectangle.
• Area is thus polymorphic- exact function called depends on number of arguments.

Question 110

C & C Plus Plus
Edit

Write in Short

1. #defineintchar
2. main ()
3. {
4.     inti =65;
5.     printf ( “sizeof (i) =%d” sizeof (i) );
6. }

Explanation

In a program

 #define int char #define replaces the string int by the macro char main (){int i = 65;printf ( “sizeof (i) =% d” sizeof (i) ) ;} Here , int value replace in char valueThen, print sizeof (i) = 1Because, character variable minimum size is 1 byte or 1 character

Developed by: