negative value assignment in an unsigned int

This is a discussion on negative value assignment in an unsigned int within the C Programming forums, part of the General Programming Boards category; Hi All If I assign any -ve value to an unsigned int variable I never find any warning while compiling... ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    3

    negative value assignment in an unsigned int

    Hi All

    If I assign any -ve value to an unsigned int variable
    I never find any warning while compiling...
    & it prints the correct value also....

    I donno the reason behind this....

    expecting your comments...

    thanks & regards
    Sanjeev

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    C doesn't warn on overflows.

    And it's probably showing up right because you're printing it with printf() using %d instead of %u which means printf() is just reading it as a signed int instead of unsigned. Try using the correct format specifier (%u) for unsigned int and you should see something different.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Need Help Please
    By YouShallNotPass in forum C++ Programming
    Replies: 3
    Last Post: 08-22-2006, 11:22 AM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21