HCL Papers: Sample Questions 53 - 54 of 57

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

Question number: 53

» Languages » C & C Plus Plus

MCQ▾

Question

What is the size of the following union? Assume that the size of int = 2, size of float = 4 and size of char = 1.

  1. Union Tag
  2. {
  3.     int a;
  4.     flaot b;
  5.     char c;
  6. };

Choices

Choice (4) Response

a.

4

b.

2

c.

1

d.

7

Answer

a.

Explanation

  • Using union data type user can store different data types in the same memory location. In union allocated memory space is equal to the member with largest size. Like here we are assuming that size of integer variable is 2, float variable is 4 and character is 1.
  • In the Tag function three different variables a, b and c are declared which are integer, float and character. Here, variable c is of float type and have largest size (4 bytes). So the total memory required to store union variable is 4 bytes.

Question number: 54

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

What will be the output of the following?

  1. main()
  2. {
  3.     inti;
  4.     char *p;
  5.     i=0X89;
  6.     p=(char *)i;
  7.     p++;
  8.     printf("%xn",p);
  9. }

Explanation

  • In the main () function one integer variable i is declared and one more character pointer p is declared. Here, variable i is defined with hex value 89. In the next statement we are defining pointer p with value at the address of i. So, now p will contain value 0X89. Then we are incrementing the pointer by one value. So, now value of p is incremented by 1. So, value in the p will be 0 × 8A. As in hex numbers 0 to 9 numbers and A to F letters are used to represent total 0 to 15 numbers.
  • A represents number 10, B represents number 11, C represents number 12, D represents number 13, E represents number 14, F represents number 15. In the printf statement we want to print the value stored in pointer p. %x is the format specifier for hex (base 16) value. So, output of the program will be 0X8A.