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>
using namespace std;
int main()
{
    int i = 10, j = 5;
    int modResult = 0;
    int divResult = 0;
    modResult = i % j;
    cout << modResult << " ";
    divResult = i/modResult;
    cout << divResult;
    return 0;
}

Error :

Floating point exception

Description :

It should give a divide by zero exception. But since the statement is 'i/modResult', where modResult is a variable it won't give this error. Instead, it returns a floating point exception.

No comments:

Post a Comment