Languages [3i Infotech Placement]: Sample Questions 227 - 228 of 546

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 227

Edit

Write in Short

Short Answer▾

What is the output of the following program?

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

Explanation

In the program

Table Shows the Program
int i = 5, j = 6, z;
  • Given the integer variables i = 5, j = 6 and z
printf ( “% d” i ++ + j) ;
  • Expression i ++ + j is treated as (i ++ + j)
  • So (5 + 6 = 11)
  • I ++ + j is equivalent to i ++ + j.
  • Not because of operator precedence but because of grammar rules, which are generally greedy.
  • The ++ + is resolved to ++ + by the compiler before expressions are parsed.
  • So the answer is 11

Question 228

Edit

Describe in Detail

Essay▾
  1. voidmain ()
  2. {
  3.     unsignedi =1;
  4.     /⚹unsigned char k =-1 ➾ k =255; ⚹/
  5.     signedj =-1;
  6.     /⚹char k =-1 ➾ k =65535 ⚹/
  7.     /⚹unsigned or signed int k =-1 ➾ k =65535 ⚹/
  8.     if (i<j)
  9.     printf("less");
  10.     elseif (i>j)
  11.     printf ("greater");
  12.     elseif (i==j)
  13.     printf ("equal");
  14. }

Explanation

  • Program defines signed and unsigned values
Table Showing the Program
unsigned i = 1;
  • define the unsigned variable i = 1
signed j =-1;
  • define the signed variable j =-1
if (i < j)

printf ( “less” ) ;

else if (i > j)

printf ( “greater” ) ;

else if (i == j)

printf ( “equal” ) ;

}

  • check the if condition

    if (1 <-1)

    printf ( “less” ) ;

  • printf prints “less” because unsigned can hold a larger positive value, and no negative value.
  • Signed integers can hold both positive and negative numbers.
  • Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative.

Developed by: