我一直在尋找一些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