Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:03:19+00:00 2026-06-06T12:03:19+00:00

Can someone explain why unsigned int is taking a negative value? An unsigned int

  • 0

Can someone explain why unsigned int is taking a negative value? An unsigned int should take only positive values.

From Wikipedia:

word, long, doubleword, longword, int

Unsigned: From 0 to 4,294,967,295 which equals 2^32 − 1

#include <stdio.h>
typedef unsigned int uint32;

int main()
{
     uint32 i;
     int x = -1;
     i = x%32;
     printf("\n\n Value of uint32 i = %d", i);
     return (0);
}

Output:

Value of uint32 i = -1

Below is the explanation which I found in cpp standard, which I am unable to interpret.

For each of the signed integer types, there exists a corresponding (but different) unsigned integer type: “unsigned char”, “unsigned short int”, “unsigned int”, and “unsigned long int,” each of which occupies the same amount of storage and has the same alignment requirements (3.9) as the corresponding signed integer type40) ; that is, each signed integer type has the same object representation as its corresponding unsigned integer type. The range of nonnegative values of a signed integer type is a subrange of the corresponding unsigned integer type, and the value representation of each corresponding signed/unsigned type shall be the same.

4 Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number of bits in the value representation of that particular size of integer

40) See 7.1.5.2 regarding the correspondence between types and the sequences of type-specifiers that designate them.

41) This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer
type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:03:21+00:00Added an answer on June 6, 2026 at 12:03 pm

    You are using the wrong flag for printf. It should be %u.

    printf("\n\n Value of uint32 i = %u", i);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain why it's best use is for prototyping? Should it not be
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can someone explain to me if I should use bcpow() instead of pow() and
Can someone explain how to iterate through all my object values with an alert?
Can someone explain me why with that query: SELECT * FROM `tags` WHERE (tag
Can someone explain this to me: char* a; unsigned char* b; b = a;
can someone explain why this isn't working? i am trying to put an unsigned
Can someone explain this simple, yet deceiving, anomaly? There are two models, where B
Can someone explain me why this works: select val1, val2, count(case when table2.someID in
Can someone explain why, in this situation, scandir is getting my directory, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.