Languages-Java [3i Infotech Placement]: Sample Questions 109 - 110 of 141

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

Question 109

Edit

Write in Short

Short Answer▾

Scanf can read ________

Explanation

  • Scanf can read any data type .
  • Use the scanf () function read string like any other data type.
  • The sacnf () function only take the first entered word.
  • The function terminates when it encounters a white space.

Example:

  1. #include <stdio.h>
  2. intmain()
  3. {
  4.     charname[20];
  5.     printf("Enter name:");
  6.     scanf("%s", name);
  7.     printf("Your name is %s.", name);
  8.     return0;
  9. }

Output:

Enter name: ABC DEF

Your name is ABC.

Question 110

Appeared in Year: 2004

Question

MCQ▾

What is the output of following piece of code?

  1. intx =2.
  2. switch (x)
  3. {
  4.     case1:System. Out. Println ( “1” );
  5.     case2:Case3:System. Out. Println ( “3” );
  6. case4:Case5:System. Out. Println ( “5” ); }

Choices

Choice (4)

a.

135

b.

35

c.

No output

d.

3

Answer

b.

Explanation

Dicleration of Integer Value X as 2
Int Declare integer value x as
Switch (x)The Switch expression should be an integer or a variable or an expression that evaluates to an integer.
case 1: System. Out. Println ( “1” ) ;In case output is printed But this will not be selected
case 2: case 3: System. Out. Println ( “3” ) ;In Case output is printed. Of course, this case would be selected, as the value of switch expression is .
case 4: Case 5: System. Out. Println ( “5” ) ;}In case output printed is would also be printed as there is no break inside 3: , so execution simply continues to Thus output will be

Developed by: