HCL Papers: Sample Questions 50 - 52 of 57

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 50

» Languages » C & C Plus Plus

MCQ▾

Question

What is the output of the following program?

  1. int x0x65;
  2. main()
  3. {
  4.     char x;
  5.     printf("%dn",x)
  6. }

Choices

Choice (4) Response

a.

Unidentified

b.

65

c.

Compilation error

d.

‘A’

Answer

b.

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 number: 51

» Languages » C & C Plus Plus

MCQ▾

Question

What are the values printed by the following program?

  1. #define dprint(exprprintf(#expr "=%dn",expr)
  2. main()
  3. {
  4.     int x=7;
  5.     int y=3;
  6.     dprintf(x/y);
  7. }

Choices

Choice (4) Response

a.

=2

b.

#2 = 2

c.

expr = 2

d.

None of the above

Answer

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 .

Question number: 52

» Languages » C & C Plus Plus

MCQ▾

Question

What is the output of the following program?

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

Choices

Choice (4) Response

a.

10,7

b.

3,6

c.

3,7

d.

10,6

Answer

c.

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.