我一直在寻找一些RobotC代码,它非常类似于C(并且我没有足够的信誉来制作新的RobotC标签),并且我遇到了 * =操作符。我已经使用了相当多的代码,但我只能得到它在C语言中是一个按位运算符。似乎没有人确切地说明它的作用,但是如果你们能够提供帮助,我会很感激。“* =”在C编程中究竟意味着什么?
rot *= 5;
这里是我找到它的代码。所有功能的作用是重新定向机器人始终面向北方。
//Turns back to North
void TurnStraight(int cdegree) //cdegree is the sensor value read by the compass sensor
{
int rot = cdegree % 360;
int mot = 1;
//stop when the NXT facing North
if (cdegree == 0){
return;
}
//reset the encoders value to avoid overflaow
clear_motor_encoders();
if (cdegree > 180 && cdegree < 360){
rot = 360 - rot;
mot = 0;
}
rot *= 5; // ratio between the circumference of the tire to the circumference of the rotation circle around itself
switch (mot){
case 1:
moveTo(rot/2,1);
break;
case 0:
moveTo(rot/2,-1);
break;
case -1:
moveTo(rot,1);
break;
}
}
void clear_motor_encoders()
{
nMotorEncoder[motorA] = 0;
}
void moveTo(int rot, int direction)
{
nSyncedMotors = synchAC;
nSyncedTurnRatio = -100;
nMotorEncoderTarget[motorA] = rot;
motor[motorA] = direction * 50;
while (nMotorRunState[motorA] != runStateIdle) ;
motor[motorA] = 0;
}
这不是我的代码当然,我只是想知道它是如何工作的。
乘以它可能很难谷歌搜索对于'* =',但是“C运营商”可以很容易地让你[维基百科](http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Compound_assignment_operators) – 2013-03-17 01:22:46
查看Steve Summit的[“Introduc tory C programming“](http://www.eskimo.com/~scs/cclass/cclass.html),过时但非常相关。你开始问,为什么你的程序崩溃是由于明显的指针问题之前,请阅读并_understand_特德Jensen的[“关于C指针和数组的指南”(http://pw1.netcom.com/~tjensen/ptr/pointers。 HTM)(也相当过时,但必不可少)。 – vonbrand 2013-03-17 03:35:26