Identify the errors in the following programs, and explain how you would correct them to
make them do what they were apparently meant to do.
a). Give two ways to x this code: 2
#include <iostream >
int main()
{
printNum(35);
return 0;
}
void printNum( int number)
{
std::cout << number;
}
int main()
{
printNum(35);
return 0;
}
void printNum( int number)
{
std::cout << number;
}
/*
The above code code will give an error as undeclared function printNum.
This is because the function was not declared above the main function.
*/
Correcetd Code:
using namespace std;
#include <iostream >
void printNum( int number)
{
std::cout << number;
}
int main()
{
printNum(35);
return 0;
}
Comments
Leave a comment