Pointers ignoring unsigned trait in C? -


i'm curious why following code returns negative numbers though every single variable , fuction initialization in program unsigned int. thought supposed positive?.

#include <stdio.h>  unsigned int main () { unsigned int ch = 0; unsigned int asteriskvalue = 0; while(ch!=27) {     ch = getch();         if (ch == 224)         {             increasedecrease(&asteriskvalue);         }     printf("%d",asteriskvalue); } }  void increasedecrease(unsigned int *value) { unsigned int upordown; upordown = getch (); if(upordown == 72)     (*value)--; else if(upordown == 80)     (*value)++; } 

i think results positive value, printing "%d" flag, tells printf interpret signed value, if casting on fly type: (signed)asteriskvalue

try printing "%u" formatting instead of "%d".


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -