Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 3 - 4 of 354

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▾

In the following code segment what will be the result of the function value of x, value of y

  1. {
  2.     unsignedintx =-1;
  3.     inty;
  4.     y =~0;
  5.     if (x == y)
  6.     printf ( “same” );
  7.     else
  8.     printf ( “notsame” );
  9. }

Choices

Choice (4)

a.

Not same

b.

Same, MAXUNIT, MAXUNIT

c.

Same

d.

Not same, MAXINT

Answer

c.

Explanation

  • In the program
Table Showing the Program
unsigned int x =-1;
  • define the unsigned integer variable x =-1
int y;
  • define the integer variable y
y = ~0;
  • ~0 is the binary representation of -1
  1. if (x == y)
  2. printf ( “same” );
  3. else
  4. printf ( “notsame” );
  5. }
  • Check the if condition
  1. if (-1 == -1)
  2. printf ( “same” );
  3. else
  4. printf ( “notsame” );
  5. }
  • So the answer is same

Question 4

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #defineprod (a, b) a ⚹b
  2. main ()
  3. {
  4.     intx =3, y =4;
  5.     printf ( “%d” prod (x +2, y − 1) );
  6. }

Explanation

In the program

Table Shows the Program
prod (a, b) a ⚹ bDefine the globally declared macro
int x = 3, y = 4;Define the integer variable x and y with values 3 and 4
printf ( “% d” prod (x + 2, y − 1) ) ;The macro expands and evaluates as:

x + 2 ⚹ y-1

x + (2 ⚹ y) -1

3 + (2 ⚹ 4) -1

3 + 8 - 1

11 - 1

10

Developed by: