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

C & C Plus Plus



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. UnionTag
  2. {
  3.     inta;
  4.     flaotb;
  5.     charc;
  6. };


Choice (4)












  • 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 8

C & C Plus Plus

Write in Short

Short Answer▾

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. }


  • 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 0x8A. 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.

Developed by: