C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]
Solution 1
"Y"
, "y"
, "n"
, and "N"
are C-style strings, which are null-terminated character arrays. When attempting to compare them, they degenerate to pointers to const char
. On the other hand, inputy
is declared as int
. This is the origin of your comparison between pointer and integer errors.
To fix the issue, compare inputy
against characters instead of strings: 'Y'
, 'y'
, 'n'
, and 'N'
(note the single quotes, rather than double quotes).
Solution 2
You have another problem. You've declared int inputy;
but you are trying to read a character by doing scanf("%c", &inputy);
. The format string %c
does not match the data type of &inputy
. If you want to read a character you should use the correct type for the input variable:
char inputy;
scanf("%c", &inputy);
Admin
Updated on June 27, 2022Comments
-
Admin about 2 years
I am a beginner C++ Programmer With Very little knowledge about C++. I Have Been Creating a Program on The IDE and Compiler: Dev-C++ 5.6.3. I have run into this error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]. I don't know what it means.
-
M.M almost 10 yearsAlso a change needs to be made, either
inputy
be achar
, orscanf("%c"
not be used -
Mike DeSimone almost 10 yearsAh yes, the confusion caused by the fact that so many "character" functions in C use
int
to pass or return the character. -
Mike DeSimone almost 10 yearsCome to think of it, if running on a little-endian platform, and if the memory used by
inputy
was initialized to0
by some means, then correct behavior will be observed even though the pointer is pointing to the wrong type (because the byte the pointer points to is the lowest-order byte of theint
). Definitely "undefined behavior" as far as the language is concerned.