While writing simple program i found strange behavior in c comparison. Here is my code:
#include <stdio.h>
#define MAXLEN 1000
void lowerrr(char inp[]);
//BQhiuIGEIBEIuo2jehgUIGIUGIUg3iuoOgklOIhp__rvknzioUFIU#Gnf%
int main(){
char inp[] = "BQhiuIGEIBEIuo2jehgUIGIUGIUg3iuoOgklOIhp__rvknzioUFIU#Gnf";
lowerrr(inp);
printf("%s",inp);
return 0;
}
void lowerrr(char inp[]){
for (int i = 0; inp[i] != '\0'; ++i){
printf("%d", ('A' <= inp[i] <= 'Z'));//always true
//printf("%d", (inp[i] >= 'A' && inp[i] <= 'Z')); work normaly
(inp[i] >= 'A' && inp[i] <= 'Z') ? inp[i]+= 'a' - 'A' : inp[i] ;
}
}
I don't understand why this comparison ('A' <= inp[i] <= 'Z') always give true (and not work normally) but this (inp[i] >= 'A' && inp[i] <= 'Z') work fine? Please explain it to me.