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

c.

Explanation

• In 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 if (x == y)printf ( “same” );elseprintf ( “not same” );} Check the if conditionif (-1 == -1)printf ( “same” );elseprintf ( “not same” );}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

 prod (a, b) a ⚹ b Define 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-1x + (2 ⚹ y) -13 + (2 ⚹ 4) -13 + 8 - 111 - 110

Developed by: