Find error in code.

Q18. Identify the errors in the following code segment:

              :

int main()

{

       cout<<”Enter two numbers: “;

       cin>>num>>auto;

       float area=length*breath;

}

Ans.

  1. Variable auto is invalid (it is a C++ reserved keyword).
  2. Variables (num, auto (though invalid)) are not defined before their usage.
  3. Even though variable area has been dynamically initialized but the variables is depends upon, that is, length and breadth have not been defined.
  4. return statement is missing.

Leave a Reply

Your email address will not be published. Required fields are marked *

82 Views
%d bloggers like this: