C 如何生成一个函数,该函数接收指向将被乘和除的数字的指针?
我知道我可以通过位向左移位进行乘法,向右移位进行除法,但让我困惑的是指向数字的函数(指针)的参数C 如何生成一个函数,该函数接收指向将被乘和除的数字的指针?,c,function,division,bit-shift,multiplication,C,Function,Division,Bit Shift,Multiplication,我知道我可以通过位向左移位进行乘法,向右移位进行除法,但让我困惑的是指向数字的函数(指针)的参数 void func(unsigned *u) { *u >>= 1; // do the operation on the unsigned value pointed by u. // u contains the address of the object (in this case, the unsigned) } 打电
void func(unsigned *u)
{
*u >>= 1; // do the operation on the unsigned value pointed by u.
// u contains the address of the object (in this case, the unsigned)
}
打电话
unsigned a = 23;
func(&a); // pass the pointer to the variable a. After the function executes,
// a will be changed as the operation is done on it.