# Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 85 - 87 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 85

C & C Plus Plus
Edit

### Describe in Detail

Essay▾

Find the output for the following C program

1. `main ()`
2. `{`
3. `    int x =20, y =35;`
4. `    x =y ++ +x ++;`
5. `    y =+ +y ++ +x;`
6. `    printf ( “%d %d” ,x, y);`
7. `}`

### Explanation

• In the program
 int x = 20, y = 35; define the integer variable x = 20 and y = 35 x = y ++ + x ++ ; here x = 35 ++ + 20 ++x = 36 + 20x = 56 y =+ + y ++ + x; here x = 56then y =+ + 35 ++ + 56y = 36 + 57y = 93 printf ( “% d % d” , x, y) ; printf prints the value of x = 56 and y = 93

## Question 86

C & C Plus Plus
Edit

### Describe in Detail

Essay▾

Find the output for the following C program

1. `main ()`
2. `{`
3. `    int x =5;`
4. `    printf ( “%d %d %d”, x, x≪2, x≫2);`
5. `}`

### Explanation

• In the program
 int x = 5; define the integer variable x = 5 printf ( “% d % d % d” , x, x << 2, x >> 2) ; As x = 5 so first % d gives 5Second % d will take value of x after left shifting it twice, and shifting is done after converting the values to binary, binary value of 5 (000101) will be left shifted twice to make it binary 20 (0010100) , so x ≪ 2 is 20As right shifting does not affect the original value of x it՚s still 5 so third % d will also show 1.

## Question 87

C & C Plus Plus
Edit

### Describe in Detail

Essay▾

Predict the output or error (s) for the following:

1. `main ()`
2. `{`
3. `    int i =300;`
4. `    char ⚹ptr=&i;`
5. `    ⚹++ptr=2;`
6. `    printf ( “%d”,i);`
7. `}`

### Explanation

In the program

 int i = 300; Given the integer variable i = 300 char ⚹ ptr = &i; The integer value 300 in binary notation is: 00000001 00101100.It is stored in memory (small-endian) as: 00101100 00000001. ⚹+ + ptr = 2; Result of the expression ⚹+ + ptr = 2 makes the memory representation as: 00101100 00000010. printf ( “% d” , i) ; So the integer corresponding to it is 00000010 00101100 ⩾ 556.

Developed by: