What does the Warning: return do integer from a pointer without casting in C?

I am writing a simple function in C, the purpose of which is to take a 6-bit number, work out the first 3 bits and based on this return "r", "w" or "o".

However, when compiling, I get this warning: "return makes an integer from a pointer without a cast." Then, when I run the program, I find that the function returns a strange character, which is definitely not one of the three that I follow.

What's going on here? Thanks in advance.

Here is my function:

char
readorwrite(int opcode)
{
    if (opcode >> 3 == 4) {
        return "r";
    } else if (opcode >> 3 == 5) {
        return "w";
    } else {
        return "o";
    }
}
+3
source share
2 answers

, "r", "w" "o" , , char [] char *. , . "r", "w" "o".

+18

const char *, , "o", char 'o'

+4

Source: https://habr.com/ru/post/1707102/


All Articles