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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inta =0;
  4.     intb =20;
  5.     charx =1;
  6.     chary =10;
  7.     if (a, b, x, y)
  8.     printf ( “hello” );
  9. }

Explanation

In the program

Table Shows the Program
int a = 0;Define the integer variable a = 0
int b = 20;Define the integer variable b = 20
char x = 1;Define the character variable x = 1
char y = 10;Define the character variable y = 10
if (a, b, x, y)
  • Check if condition.
  • The comma operator has associativity from left to right.
  • Only the rightmost value is returned and the other values are evaluated and ignored.
  • Thus the value of last variable y is returned to check in if.
  • Since it is a non-zero value if becomes true
printf ( “hello” ) ;“hello” will be printed.

Question 260

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     constinti =4;
  5.     floatj;
  6.     j =+ +i;
  7.     printf ( “%d %f” i, ++ j);
  8. }

Explanation

Compiler error

  • In the program
Table Shows the Program
const int i = 4;Given the constant integer i = 4
float j;Given Floating variable j
j =+ + i;
  • Here change the value if I but I is a constant
  • Cannot change the value of constant
  • So the answer is compiler error.

Developed by: