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

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Is the following code legal?

  1. structa
  2. {
  3.     intx;
  4.     structa ⚹b;
  5. }

Explanation

In this code

Table Shows the Program
struct a

{

int x;

struct a ⚹ b;

}

  • ⚹ b is a pointer to type struct a and so it is legal
  • The compiler knows, the size of the pointer to a structure even before the size of the structure is determined
  • The pointer to any type is of same size.
  • This type of structures is known as ‘self-referencing’ structure.

Question 91

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     chara[100];
  4.     a[0] =‘a’ a[1] =‘b’ a[2] =‘c’ a[4] =‘d’ ;
  5.     abc (a);
  6. }
  7. abc (chara[])
  8. {
  9.     a ++;
  10.     printf ( “%c” ⚹a);
  11.     a ++;
  12.     printf ( “%c” ⚹a);
  13. }

Explanation

In the program

Table Shows the Program
char a [100] ;Declare the character array a [100] ;
a [0] = ‘a’ a [1] = ‘b’ a [2] = ‘c’ a [4] = ‘d’ ;Define the characters in the array.
abc (a) ;Applying abc (a) function
abc (char a [] )

{

a ++ ;

printf ( “% c” ⚹ a) ;

a ++ ;

printf ( “% c” ⚹ a) ;

}

In the abc () function

First the base address is modified only in function and as a result ‘a’ points to ‘b’ then after incrementing to ‘c’ .

So, bc will be printed.

Developed by: