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

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     show ();
  4. }
  5. voidshow ()
  6. {
  7.     printf ( “I'm the greatest” );
  8. }

Explanation

  • Compiler error: Type mismatch in redeclaration of show.
  • In a program
    Table Showing the Program
    1. main ()
    2. {
    3.     show ();
    4. }
    When the compiler sees the function show it doesn՚t know anything about it.

    So the default return type (i.e. … int) is assumed.

    1. voidshow ()
    2. {
    3.     printf ( “Imthegreatest” );
    4. }
    However, when compiler sees the actual definition of show mismatch occurs.

    Since it is declared as void.

    Hence the error.

  • This type of mistakes solutions are as bellows:
    1. Declare void show () in main () .
    2. Define show () before main () .
    3. Declare extern void show () before the use of show () .

Question 286

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Is the following code legal?

  1. structa
  2. {
  3.     intx;
  4.     structab;
  5. }

Explanation

  • It is not legal for a structure to contain a member that is of the sametype as in this case.
  • Because this will cause the structure declaration to be recursive without end.
  • It is ok for structure to contain a pointer to itself.

Question 287

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the difference between class and structure?

Explanation

Difference between Class and Structure
ClassStructure
Can inherit from another class.Does not support inheritance.
Supports all types of constructor and destructor.Supports only the parameterized constructor.
Members of class can be initialized directly.Members of structure cannot initialize directly.
Not created without using the new keyword.It can be created without using the new keyword.

Developed by: