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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inti =4, j =7;
  4.     j =j|| i ++ && printf ( “YOUCAN” );
  5.     printf ( “%d %d”, i, j);
  6. }

Explanation

In the program

Table Shows the Program
int i = 4, j = 7;
  • Given the integer variable i = 4 and j = 7
j = j|| i ++ && printf ( “YOU CAN” ) ;
  • The boolean expression needs to be evaluated only till the truth value of the expression is not known.
  • J is not equal to zero itself means that the expression՚s truth value is 1.
  • Because it is followed by || and true || (anything) ⩾ true, thus (anything) will not be evaluated. So the remaining expression is not evaluated and so the value of I remains the same.
  • Similarly when && operator is involved in an expression, it becomes false any of the operands become false- the whole expression՚s truth value becomes false and hence the remaining expression is notevaluated. Thus, false && (anything) ⩾ false where (anything) will not be evaluated.
printf ( “% d % d” , i, j) ;printf prints the value of i = 4 and j = 1

Question 265

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     unsignedinti =10;
  4.     while (i-->= 0)
  5.     printf ( “%u” i);
  6. }

Explanation

10 9 8 7 6 5 4 3 2 1 0 65535 65534 …

In the program

Table Shows the Program
unsigned int i = 10;Since i is an unsigned integer it can never become negative.
while (i-- >= 0)

printf ( “% u” i) ;

So the expression i-- >= 0 will always be true, leading to an infinite loop.

Developed by: