• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer

Mr.CodeHunter

Programming and Code Solutions

  • Home
  • C++
  • About Us
  • Contact Us
  • Privacy Policy

iso c++ forbids comparison between pointer and integer [SOLVED]

May 23, 2021 by Admin Leave a Comment

Many time during running c++ program you get comparison errors. Sometimes it will be iso c++ forbids comparison between pointer and integer or sometimes you will get iso c++ forbids comparison between pointer and integer [-fpermissive]. Here we will see when these type of c++ compiler error occurs and how to resolve these iso c++ forbids comparison between pointer and integer errors from c++ program.

1. iso c++ forbids comparison between pointer and integer

#include <iostream>
using namespace std;
int main() {
    char str[2];
    cout << "Enter ab string";
    cin >> str;
    if (str == 'ab')
    {
         cout << "correct";
    } else {
        cout << "In correct";
    }
    return 0;
}

Output:

Here during string comparison you are getting compilation errors. “error: ISO C++ forbids comparison between pointer and integer [-fpermissive]”

SOLUTION FOR ERROR:

if(str==’ab’), here str is const char* type. Which is array of character.
Here ‘ab’ is consider as integer value. ideally it should be as constant string value.
Because of single quote it is considered as integer value.
So for comparison you need to use double quote “ab”. And declare it as string variable.
Now you can compare using strcmp(str, “ab”) or using str == “ab”.

#include <iostream>
using namespace std;
int main() {
    string str;
    cout << "Enter ab string: ";
    cin >> str;
    if (str == "ab")
    {
         cout << "correct";
    } else {
        cout << "In correct";
    }
    return 0;
}

Output:

2. error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

#include <iostream>
using namespace std;

int func(int i, int j) {
    int val = 1;
    if (val > func) {
      return (val+1);
    }
    return val;
}

int main() {
  int val = func(3,6);
  return 0;
}

Output:

SOLUTION FOR ERROR:

If you see if condition if(val > func), then here we have by mistake given function name which has different datatype then integer value.

So our comparison is wrong. Whenever any comparison is wrong you will get this error. Ideally here we need to compare with some integer value.

    int val = 1;
    int IntValue = 0;
    if (val > IntValue) {
      return (val+1);
    }
    return val;

Here we have removed function name and comparing it with Integer value. Now that error will be resolved.

CONCLUSION:

Whenever you are getting any error similar to ISO C++ forbids comparison between pointer and integer [-fpermissive], Then check that comparison condition. You will get to know that comparison condition is mismatch with two different data type of variables. For resolving c++ forbids comparison error you just need to compare similar kind of variables in conditions. I hope given two examples will be helpful for your to find out your code issue. If you like this article then please check other c++ related information in given website. Happy Coding !! ๐Ÿ™‚

Filed Under: All C++, C++

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search here

Social Media

  • Facebook
  • YouTube

SEE MORE

Fibonacci sequence c++

Fibonacci Sequence c++ is a number sequence which created by sum of previous two numbers. First two number of series are 0 and 1. And then using these two number Fibonacci series is create like 0, 1, (0+1)=1, (1+1)=2, (2+1)=3, (2+3)=5 …etc Displaying Fibonacci Series in C++ ( without recursion) Output: From given output we […]

map c++

C++ Map [Learn by Example]

C++ map is part of Standard Template Library (STL). It is type of Associative container. Map in c++ is used to store unique key and it’s value in data structure. But if you want to store non-unique key value then you can use Multi Map in c++. Let us first understand in detail what is […]

how to copy paste in turbo c++ ?

There are many different C++ IDE are available but still many students are using Turbo c++ for learning c/c++ programming languages. During using Turbo c++ if you are beginner you will be confuse for how to copy and paste in turbo c++ or if you have already copy some content and you want to paste […]

C++

return 0 c++

There are two different scenario return statement is used inside c++ programming. We can use return 0 c++ inside main() function or other user defined functions also. But both have different meanings. return 0 c++ used inside Main function return 0 c++ used inside other user defined function What is meaning of return 0 and […]

C++

c++ expected a declaration [ SOLVED]

When any function or statement is not in scope or we have used wrong syntax then possibly you will get error for c++ expected a declaration in your code. Main reasons for errors are: Incorrect use/declaration inside namespace Statements are added out of scope Required statement need to add inside main/function Solution-1 | Expected a […]

C++

c++ cannot open source file “errno.h” [SOLVED]

Normally you will face c++ cannot open source file “errno.h” in MS Visual Studio c++ projects. These are some solutions to remove opening errors for “errno.h” file. I got the errors to go away by installing the Windows Universal CRT SDK component, which adds support for legacy Windows SDKs. You can install this using the […]

Footer

DISCLAIMER

The information contained on https://www.mrcodehunter.com is for general information purposes only. We assumes no responsibility for errors or omissions in the contents on the Service.

SITEMAP XML

Sitemap

Recent

  • Fibonacci sequence c++
  • C++ Map [Learn by Example]
  • how to copy paste in turbo c++ ?
  • return 0 c++
  • c++ expected a declaration [ SOLVED]

Search

Copyright © 2025 ยท Mr Code Hunter