Languages-C & C Plus Plus [HCL Placement]: Sample Questions 5 - 6 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 5

C & C Plus Plus

Question

MCQ▾

Which of the following about the following two declarations is true?

i) int ⚹ F ()

ii) int (⚹ F) ()

Choices

Choice (4)

a.

The first declaration is a function returning a pointer to an integer and the second is a pointer to function returning int

b.

i & ii are identical

c.

i & ii are different ways of declaring pointer to a function

d.

The first is a correct declaration and the second is wrong

Answer

a.

Explanation

In the first statement one function F is returning to a pointer which is returning an integer value. In the second statement, pointer F is returning to a function which is again returning to an integer value. Both declarations are different from each other, but both are correct.

Question 6

C & C Plus Plus

Question

MCQ▾

What is the output of the following program?

  1. main()
  2. {
  3.     inta=10;
  4.     intb=6;
  5.     if(a=3)
  6.     b++;
  7.     printf("%d %dn",a,b++);
  8. }

Choices

Choice (4)

a.

3,6

b.

3,7

c.

10,6

d.

10,7

Answer

b.

Explanation

  • In the main () function two integer variables are defined with a = 10 and b = 6.
  • In the if statement we are not checking any condition but passing value 3 to variable a.
  • b ++ is the post increment operator. After its execution value of b will be incremented by 1. So, now value of b will be
  • In the printf statement we want to print the value of a and b ++ with format specifier % d.
  • Value of a is now 3 and b ++ is post increment operator, where value of b is substituted first and then it is incremented by 1. So, 7 will be printed.
  • Output of the program will be 3,7.

Developed by: