Languages-C & C Plus Plus [HCL Placement]: Sample Questions 11 - 12 of 12

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

Question 11

C & C Plus Plus

Question

MCQ▾

What is the output of the following program? (. has been used to indicate a space)

  1. main()
  2. {
  3.     chars[]="Hello,.World";
  4.     printf(%15.10s",s);
  5. }

Choices

Choice (4)

a.

… . Hello, . Wor

b.

Hello, . Wor … .

c.

Hello, . World …

d.

None of the above

Answer

a.

Explanation

  • In the main () function one string variable is defined, s with “Hello, World” .
  • The printf statement will print 15 characters of string. Here, given string is shorter than 15. If the given string is smaller than the size, then the “empty” positions will be filled with “white space” . But it will print only 10 characters. Here, white space is added in the beginning of the output.
  • So, output will be … . Hello, . Wor

Question 12

C & C Plus Plus

Question

MCQ▾

Find the output for the following C program

  1. inti =10
  2. main()
  3. {inti =20,n;
  4.     for(n=0;n<=i;)
  5.     {inti=10;
  6.         i++;
  7.     }
  8.     printf("%d", i);
  9. }

Choices

Choice (4)

a.

20

b.

10

c.

12

d.

All of the above

Answer

a.

Explanation

  • Firstly, one integer i is defined with value 10. In the main () function one more time variable i is defined with 20 and variable n is declared. In for loop n is initialized with 0. In the condition value of n is compared with value of i.
  • If it is less than or equal to i then i will be initialized with 10 and gets incremented. After the complete execution of for loop, we want to print the value of i, which is in the main () function. Here, variable i is initialized with 20 so, 20 gets printed on the screen.

Developed by: