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

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

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -