c - The return value of function returning long long unsigned int is incorrect -


when call function wordtoint(c) main, return value different it's printing inside function.

main() {     long long  unsigned item;     char c[6] = "abcde";     item = wordtoint(c);     printf("main  item :%llu\n",item); }  long long unsigned wordtoint(char *c) {     long long unsigned int k,item=0;     int i,len;     int j,p=0;     len = (int) strlen(c);      for(i = len-1;i>=0;i--)     {         if(c[i] == 'c')             j = 42;         else if(c[i] == '*')             j = 99;         else             j = (int) c[i];         j = j%100;         k = pow(100,p);         p++;         item = item + (j*k);     }      printf("function item :%llu\n",item);     return item; } 

the output of program is:

function item :6566676869 main  item :18446744071686293893 

can tell me why there inconsistency in output?

first -- pay attention compiler's warnings, matter!

answer -- since didn't prototype wordtoint() before using it, compiler warned had not been prototyped , assumed function returned int (which smaller long long)... got int value returned, rather long long. value printed within function correct because function knew proper type.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -