I have the following piece of code:
int ret() {
    int x = 010;
    int y = 4;
    int z = x | y;
    return z;
}
When x = 010, this function returns 12. However, on changing x to 10, 14 is returned. Why is this so?
I have the following piece of code:
int ret() {
    int x = 010;
    int y = 4;
    int z = x | y;
    return z;
}
When x = 010, this function returns 12. However, on changing x to 10, 14 is returned. Why is this so?
The OR operator is a red-herring: the issue is elsewhere.
010 is an octal literal due to the leading 0. In decimal, this is 8.
So x has the value 8 in decimal. And 8 | 4 is 12.
10 is a decimal literal. And 10 | 4 is 14.