Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Monday, January 24, 2011

Identify the error in the following code snippet.

Code Snippet :

#include<iostream>
#define pi 3.14
using namespace std;
int squareArea(int &);
int circleArea(int &);
int main()
{
    int a = 10;
    cout << squareArea(a) << " ";
    cout << circleArea(a) << " ";
    cout << a << endl;
    return 0;
}
int squareArea(int &a)
{
    return a *== a;
}
int circleArea(int &r)
{
    return r = pi * r * r;
}

Error :

expected primary-expression before '=' token.

Description :

In function 'squareArea', the expression 'a*==a' is wrong,instead it should  be 'a*=a', which is equivalent to ' a = a * a '.

No comments:

Post a Comment