retagged by
391 views
3 votes
3 votes
#include<stdio.h>
int main()
{
    char c = 125;
    c = c+10;
    printf("%d", c);
    return 0;
}

in this we know -121 is printed also know the logic

but what will be in

int main()
{
    char c = 125;
    c = c+10;
    printf("%u", c);
    return 0;
}

plz explain with logic

retagged by

1 Answer

2 votes
2 votes
char c=125=01111101

c=c+10=01111101+1010

c=10000111

now value of 'c' will be printed uaing %u specifier, but %u specifier wants the provided input to be of size of int..

therfore we will promote the value of 'c' to 4 bytes using 2's complement sign bit extension technique..

value after performing sign bit extension(4 bytes) c=11111.....10000111, now its unsigned value is 4294967175 which will get printed

Related questions

1 votes
1 votes
1 answer
2
jugnu1337 asked May 10, 2022
290 views
SOURCE NAME::: UNDERSTANDING POINTER IN C (BOOK) BY YASHWANT KANETKARmy answer is C am i right?
1 votes
1 votes
0 answers
3
aakash pandey asked Apr 30, 2022
292 views
We use character array to declare string in C. So, if I declare an array likecharacter ch[ ] = {‘a’,’k’,’a’,’/o’};and try printing ch[3] like :printf(“%...
0 votes
0 votes
0 answers
4
Anirudh Kaushal asked Apr 6, 2022
202 views
#include<stdio.h struct marks { int p:3; int c:3; int m:2; }; void main() { struct marks s = {2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); }What does p:3 means here ?