user2744260
user2744260

Reputation:

Strange syntax flaw in mingw

AT LINE 23- cout<"" doesnt give any error instead removing this statement produces abnormal output. i have tried it in CodeBlocks using mingw32. when i remove this it gives- Process returned 1984687287 (0x764DF487)

#include<iostream>
#include<stdio.h>

using namespace std;

int ispalin(long num)
{
    long sum=0,n;
    short rem;
    n=num;

    while(n>0) {
        rem=n%10;
        sum=sum*10+rem;
        n/=10;
    }

    if(sum==num)return 1;
        return 0;
}

int main()
{
    int n=1;
    for(int i=999;i>=1;i--) {
        for(int j=999;j>=1;j--)
        {
            if((i*j)<=n)
            {
                cout<""; // LINE 23
                break;
            }
            if((i*i)<=n)
            {
                printf("%d",n);
                return 0;
            }
            if(ispalin(i*j))
            {
                n=i*j;
                cout<<n<<"\n";
                break;
            }
        }
    }
    return 1;
}

Upvotes: 0

Views: 70

Answers (2)

P0W
P0W

Reputation: 47784

For the insertion operator

if((i*j)<=n){
    cout<<"";
         ^ Need one more <  
   ...
     }

on some platform cout (implicitly void*) object might get compared with empty string with < giving a boolean statement

And it throws error for me with Mingw 4.7.2

Upvotes: 2

Benjamin Lindley
Benjamin Lindley

Reputation: 103693

It doesn't give an error because it's a legal, albeit fruitless, statement. ostream objects are implicitly convertible to void*. So that expression results in a comparison between a void* and a const char*, which is legal.

As for your error when you remove the statement, I cannot reproduce it.

Upvotes: 0

Related Questions