Languages [HCL Placement]: Sample Questions 7 - 8 of 13

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

Question MCQ▾

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)

a.

3,6

b.

3,7

c.

10,6

d.

10,7

Edit

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.

Question 8

Question MCQ▾

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)

a.

2

b.

1

c.

7

d.

4

Edit

Answer

d.

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.