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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #if something == 0
  2. intsome =0;
  3. #endif
  4. main ()
  5. {
  6.     intthing =0;
  7.     printf ( “%d %d” some, thing);
  8. }

Explanation

In the program

Table Shows the Program
#if something == 0

int some = 0;

#endif

  • Preprocessor expressions are not the same as the ordinary expressions.
main ()

{

int thing = 0;

printf ( “% d % d” some, thing) ;

}

  • If a name is not known the preprocessor treats it to be equal to zero.
  • So, the answer is 0 0.

Question 73

C & C Plus Plus
Edit

Write in Short

Short Answer▾
  1. main ()
  2. {
  3.     inti =400, j =300;
  4.     printf( “%d. %d” );
  5. }

Explanation

  • In a program
Table Shows the Program
int i = 400, j = 300;Assign the integer variables I and j value.
printf ( “% d. % d” ) ;Printf takes the values of the first two assignments of the program
  • Any number of print՚s may be given.
  • All of them take only the first two values.
  • If more number of assignments given in the program, then printf will take garbage values.

Question 74

C & C Plus Plus
Edit

Write in Short

Short Answer▾
  1. main ()
  2. {
  3.     char ⚹p;
  4.     printf ( “%d %d” sizeof ( ⚹p), sizeof (p) );
  5. }

Explanation

  • In a program the size of () operator gives the number of bytes taken by its operand.
    Table Shows the Program
    char ⚹ pP is the character pointer

    Which needs one byte for storing its value

    printf ( “% d % d” sizeof (⚹ p) , sizeof (p) )Here, sizeof (⚹ p) gives a value of 1

    And it needs two bytes to store the address of a character pointer sizeof (p) gives 2.

  • So the Answer is 1 2

Developed by: