C,What is the difference between unsigned int(a)^unsigned int(b) and unsigned int(a^b)? -
in test platform , write program bellow:
int a, b; scanf_s("%d%d",&a,&b); unsigned int c = a^b;//this can not pass unsigned int c = unsigned int(a)^unsigned int(b) //this can pass int cnt = 0; while (c){ cnt++; c = c&(c-1); } printf("%d\n",cnt);
thanks,
there serious syntax error in program doubt compiled try following program , should work fine.
following issues there in code.
c
declared twicecasting of
int
unsigned int
had mistakeint main() { int a, b; scanf_s("%d%d",&a,&b); unsigned int c = a^b;//this can not pass c = (unsigned int)a^( unsigned int )b;//this can pass int cnt = 0; while (c){ cnt++; c = c&(c-1); } printf("%d\n",cnt); return 0; }
Comments
Post a Comment