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

Write in Short Short Answer▾

What are the advantages of using unions?

Edit

Explanation

  • Advantages is in terms of the memory.
  • If a union & structure have one int and one float, then the size of the structure is sum of its members-10 (2 ⚹ 3 + 4) , the size of the union is only 4- that is the size of its largest member (the size of the float, the largest one in this union) .

Question 178

Write in Short Short Answer▾

  1. main ()
  2. {
  3. printf (“ab”);
  4. printf (“⧵bsi”);
  5. printf (“ha”);
  6. }
Edit

Explanation

  • In a program = new line
  • ⧵b = backspace
  • = linefeed or carriage return⧵
Table Shows the Program
printf ( “ab” ) ;First print to ab
printf ( “⧵bsi” ) ;Now the handle backspace

(NOTE: that even through it is “non-erase” , the next character to be output would overwrite what was backspaced over)

Now print asi

printf ( “ha” ) ;Now, a carriage return means to go back to the beginning of the line

So, the “ha” overwrites the “as” in “asi”

  • So, the answer is “hai”

Question 179

Write in Short Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3. int i =0;
  4. int j =0;
  5. if (i && j ++ )
  6. printf ( “%d..%d”, i ++, j);
  7. printf(” %d..%d”, i, j);
  8. }
Edit

Explanation

In the program

Table Shows the Program
int i = 0;

int j = 0;

  • Define the value of i is 0 and j is 0- this information is enough to determine the truth-value of the boolean expression.
  • So, the statement following the if statement is not executed.
printf ( “% d. . % d” , i, j) ;The values of i and j remain unchanged and get printed.