Saturday, 21 October 2017

Char overflow

#include
void main(){
    unsigned char c1=260;==>0......255
    unsigned char c2=-6;
    printf("%d  %d",c1,c2);
}

Output: 4   250 
#include
int main(){
    signed char c1=130;===>-128,-127.....0....127
    signed char c2=-130;
    printf("%d  %d",c1,c2);
    return 0;
}
Output: -126   126
 

No comments:

Post a Comment