In C Programming, What is the most efficient way to count the number of bits which are set in a value?
What is the differnce between " const char * " and " char * const "?
There is no difference between
const char *
and
char const *
They are both pointers to constant chars. It is merely a style preference on which one to use,
The third variation would be
char * const
This is different than the first 2, This is a constant pointer.
With the first 2, you can make the pointer point to any char variable, but you can't change that variable's value.
eg
char x,y;
const char * p = %26amp;x;
p = y; //legal
*p = 'a'; //illegal
A constant pointer is the opposite. You can only set the pointer location at declaration time, but you can dereference and change the value. eg
char x,y;
char * const p = %26amp;x;
*p = 'a'; //legal
p = %26amp;y ;// illegal
As for counting the number of bits set. I'm with Scottso. I usually just use bit shifts.
Reply:1: i dont beleive there is a difference (not sure)
2: i use bitshift and mod by 2, idk if it is most efficient tho
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment