The Gateway to Computer Science Excellence
0 votes
How is the output still -4? when we are  storing it in an unsigned int here shouldn’t it be converted to 2’s complement and then the absolute value of it be the result?

int main()
    unsigned int num = -4;
    printf("%d", num);
    return 0;
in Programming by (369 points) | 53 views

you are defining num as unsigned int but you are using format specifier for signed int %d

#include <stdio.h>
int main()
    unsigned int num = -4;
    printf("%u", num);
    return 0;

Is the code which will give output as 4294967292. $ \ \ \ (2^{32} - 4)$

Aha! Got it thanks!

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,382 answers
105,323 users