Languages [3i Infotech Placement]: Sample Questions 316 - 318 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 316

Write in Short Short Answer▾

How can we do validation of the field in a perfect case?

Edit

Explanation

  • Validation can be called each time before throwing the object to the server for processing. If it returns true further processing can be done.
  • This is ideal solution, but it brings overhead of code, time and effort.

Question 317

Question MCQ▾

What is the output of following block of program?

  1. boolean var =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

Edit

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 318

Describe in Detail Essay▾

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

  1. char someFun()
  2. { char temp =“string constant”; return temp; } int main() { puts(someFun()); }
Edit

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.