Question #342878

Find the error(s) in each of the following program segments and explain how the error(s) can be corrected: (i) int function1() { cout << "Inside function function1 " <<

endl; int function2() { cout << "Inside function function1 " << endl; } }


Expert's answer

  1. error. The type of functions is int, so it has to return an integer value.
  2. error. The namespace of cout and endl is std. std::cout instead of cout, std::endl instead of endl
  3. error. Nested functions aren't allowed. You can use a lambda expression though.

So the fixed code would be

int function2() { 
    std::cout << "Inside function function1 " <<std::endl;
    return 0;}


int function1() { 
    std::cout << "Inside function function1 " <<std::endl; 
    function2();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS