3i Infotech Placement: Sample Questions 736 - 737 of 1245

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

Question 736

Question

MCQ▾

What is the output of following block of program?

  1. booleanvar =false.
  2. if (var =true)
  3. {
  4.     System. Out. Println ( “TRUE” );
  5. }
  6. else
  7. {
  8.     System. Out. Println ( “FALSE” );
  9. }

Choices

Choice (4)

a.

Run-time Error

b.

True

c.

Compilation Error

d.

False

Answer

b.

Explanation

Table of Block of Program
Boolean var = falseDeclares boolean variable is false
If (var = true)If variable is true
  1. {
  2.     System. Out. Println ( “TRUE” );
  3. }
Print true. Because variable is set to true in the if argument this command is executed
else
  1. {
  2.     System. Out. Println ( “FALSE” );
  3. }
Otherwise print false. The else part is not executed

Question 737

Edit

Describe in Detail

Essay▾

Predict the output or error (s) for the following:

  1. char ⚹someFun()
  2. { char ⚹temp =“stringconstant”; returntemp; } intmain() { puts(someFun()); }

Explanation

  • In the program
Table Showing the Program
puts (someFun () ) ;
  • The puts function includes someFun () function
  • int puts (const char ⚹ str) writes a string to stdout up to but not including the null character.
char ⚹ someFun ()

{char ⚹ temp = “string constant” ; return temp;}

  • The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack.
  • So this doesn՚t lead to dangling pointers.

Developed by: