Q. Write a function to check weather a string is palindrome or not. The function will return 'y' if the passed string is a palindrome otherwise 'n' will be returned. The prototype of the function is given below:
char palindrome(char string[]);
Write a function to declare and obtain a string from the user and execute the above declared function.
that returns false for non-palindromes and causes stack overflow for palindromes over 1 character long...I'm not even going to begin to try to find out why as that code just fries my brain O_o
As I sat down on my desktop chair and opened up VC++, I remembered why I hated VC++. After a few attempts at making it do what I want, I gave up (project refused to let me add files to it). Instead, I just managed to compile the given code from above on the old-ass MingW compiler that bundles with Bloodshed Dev-Cpp.
0xFE is hexadecimal for 254.
>> is a right-bitshift.
'\a' is a character constant.
'\a' = 7
So the above would be 254>>7, which is a constant and equals 1.
Explanation of bitshifting in 254>>7:
1 2 3 4 5 6 7 8 9 10
254 = 111111102
11111110
87654321
Add 7 zeroes in front while the length remains 1 to 8 will get you this binary number:
000000011111110
87654321
Everything that goes beyond the 1 is thrown away. The result is converted back to decimal and is in thiscase 1.
0xFF<<('F'-'U'-'C'+'K');
0xFF<<-7; //warning: left shift count is negative
"The behaviour [of a shift operation] is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."
I get three warnings in the line containing the function
C4804: '<' : unsafe use of type 'bool' in operation
C4293: '>>' : shift count negative or too big, undefined behavior
C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)