Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:19:46+00:00 2026-05-29T21:19:46+00:00

I am trying to compile the following code on Ubuntu (64-bit), with Code::Blocks 10.05

  • 0

I am trying to compile the following code on Ubuntu (64-bit), with Code::Blocks 10.05 as IDE:

#include <iostream>
using namespace std;
int main() {
    char a[2];
    cout << "enter ab ";
    cin >> a;
    if (a == 'ab') // line 7
    {
         cout << "correct";
    }
    return 0;
}

On line 7, my compiler gives me the error “ISO C++ forbids comparison between pointer and integer [-fpermissive]”.

Why doesn’t this work? I know I could use an std::string to work around the problem, but I want to understand the current problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:19:47+00:00Added an answer on May 29, 2026 at 9:19 pm

    char a[2] defines an array of char‘s. a is a pointer to the memory at the beginning of the array and using == won’t actually compare the contents of a with 'ab' because they aren’t actually the same types, 'ab' is integer type. Also 'ab' should be "ab" otherwise you’ll have problems here too. To compare arrays of char you’d want to use strcmp.

    Something that might be illustrative is looking at the typeid of 'ab':

    #include <iostream>
    #include <typeinfo>
    using namespace std;
    int main(){
        int some_int =5;
        std::cout << typeid('ab').name() << std::endl;
        std::cout << typeid(some_int).name() << std::endl;
        return 0;
    }
    

    on my system this returns:

    i
    i
    

    showing that 'ab' is actually evaluated as an int.

    If you were to do the same thing with a std::string then you would be dealing with a class and std::string has operator == overloaded and will do a comparison check when called this way.

    If you wish to compare the input with the string “ab” in an idiomatic c++ way I suggest you do it like so:

    #include <iostream>
    #include <string>
    using namespace std;
    int main(){
        string a;
        cout<<"enter ab ";
        cin>>a;
        if(a=="ab"){
             cout<<"correct";
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compile the following program: #include <iostream> int main(){ std::cout <<
I am trying to compile the following code on Linux using gcc 4.2: #include
When trying to compile the following code #include <thread> #include <iostream> void foo() {
When I compile the following code with g++ #include <CoreServices/CoreServices.h> int main(int argc, char
I'm trying to compile the following minimal C code on ubuntu 10.10: #include <sys/capability.h>
Hello I am trying to compile the following code, #include <stdio.h> #include <string.h> int
When trying to compile the following code in LINQPad : void Main() { DriveInfo.GetDrives().Select(GetProviderName).Dump();
I am trying to compile the following code using clang but got the following
I have the following code which i m trying to compile: #include <boost/filesystem/convenience.hpp> #include
I'm trying to compile the following snippet of code: #include <boost/filesystem/path.hpp> //Other includes snipped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.