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

C & C Plus Plus

Question

MCQ▾

What is the output of the following program?

1. intx=0x65;
2. main()
3. {
4.     charx;
5.     printf("%dn",x)
6. }

Choices

Choice (4)

a.

Unidentified

b.

‘A’

c.

Compilation error

d.

65

d.

Explanation

• Here, integer x is defined with hex value 65, which is the ascii value of letter A.
• In the main function one character variable x is declared
• In the printf function we want to print the value of x which is a character.
• The format specifier is % d, which is for integer value.
• So, output will be 65.

Question 4

C & C Plus Plus

Question

MCQ▾

What are the values printed by the following program?

1. #definedprint(expr) printf(#expr"=%dn",expr)
2. main()
3. {
4.     intx=7;
5.     inty=3;
6.     dprintf(x/y);
7. }

Choice (4)

a.

= 2

b.

#2 = 2

c.

expr = 2

d.

All of the above

a.

Explanation

• In the main () function two integers are initialized, i.e.. x = 7, y = 3
• In the dprintf function we are passing x/y as expr.
• In that function we want to print the value of expr.
• Here, as x = 7 and y = 3 and both are integer variables their division will also result in an integer.
• Here, % d is the format specifier of integer.
• results into 2.333333 … but as variables and result is integer it will be 2 only.
• So, output will be .

Developed by: