




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ExpressionsAn expression consists of one or more operands and operation characters. An expression can be written in several lines.Example: a+; b = 10; x = (y*z)/w;Note: An expression that ends with a semicolon is an operator.Arithmetical operations Sum of values i = j + 2; Difference of values i = j - 3; Changing the operation sign x = x; Product of values z = 3 * x; Division quotient i = j / 5; Division remainder minutes = time % 60; Adding 1 to the variable value i+; Subtracting 1 from the variable value k-;The operations of adding/subtracting 1 cannot be implemented in expressions.Example: int a=3; a+; / valid expression int b=(a+)*3; / invalid expressionThe operation of assignmentNote: The value of the expression that includes this operation is the value of the left operand following the bind character. Assigning the y value to the x variable y = x; Adding x to the y variable y += x; Subtracting x from the y variable y -= x; Multiplying the y variable by x y *= x; Dividing the y variable by x y /= x; Module x value of y y %= x; Logical shift of y representation to the right by x bit y = x; Logical shift of y representation to the left by x bit y = x; Bitwise operation AND y &= x; Bitwise operation OR y |= x; Bitwise operation exclusive OR y = x;Note: There can be only one operation of assignment in the expression. You can implement bitwise operations with integer numbers only. The logical shift operation uses values of x less than 5 binary digits. The greater digits are rejected, so the shift is for the range of 0-31 bit.Operations of relationThe logical value FALSE is represented with an integer zero value, while the logical value TRUE is represented with any value different from zero.The value of expressions containing operations of relation or logical operations is a 0 (FALSE) or a 1 (TRUE). True if a equals b a = b; True if a doesnt equal b a != b; True if a is less than b a b; True if a is less than or equals b a = b;Boolean operationsThe operand of negation NOT (!) must be of arithmetic type; the result equals 1 if the operand value is 0; the result equals to 0 if the operand is different from 0. / True if a is false. if(!a) Print(not a);The logical operation OR (|) of values k and 1. The value k is checked first, the value 1 is checked only if k value is FALSE. The value of this expression is TRUE if the value of k or 1 is TRUE.Example: if(xl) Print(out of range);The logical operation AND (&) of values x and y. The value x is checked first; the value y is checked only if k value is TRUE. The value of this expression is TRUE if the values of both x and y are TRUE.Example: if(p!=x & py) Print(TRUE); n+;Bitwise operationsOnes complement of variables values. The value of the expression contains 1 in all digits where n contains 0; the value of the expression contains 0 in all digits where n contains 1. b = n;Binary-coded representation of x is shifted to the right by y digits. The right shift can be arithmetical (the digits on the right that get free are filled with the value of the sign position) or logical depending on the implementation. However, the right shift of integer non-sign numbers is sure to be a logical one and the free digits on the right will be filled with zeros.Example: x = x y;The binary-coded representation of x is shifted to the right by y digits; the free digits on the right will be filled with zeroes. Example: x = x y;Bitwise operation AND of binary-coded x and y representations. The value of the expression contains 1 (TRUE) in all digits where both x and y arent equal to zero; the value of the expression contains 0 (FALSE) in all other digits.Example: b = (x & y) != 0);Bitwise operation OR of binary-coded x and y representations. The expression contains 1 in all digits where x and y not equals 0; the value of the expression contains 0 in all other digits.Example: b = x | y;Bitwise operation EXCLUSIVE OR of binary-coded x and y representations. The expression contains 1 in all digits where x and y have different binary values; the value of the expression contains 0 in all other digits.Exapmle: b = x y;Note: Bitwise operations are executed with integers only.Other operationsIndexing. At addressing to i element of array, the value of the expression equals the value of the variable number i.Example: arrayi = 3; /Assign the value of 3 to array element with index i. /Mind that the first array element /is described with the expression array 0.The call of function with x1,x2,xn arguments. The expression accepts the value returned by the function. If the returned value is void type, you cannot place such function call on the right in the assignment operation. Mind that the expressions x1,x2,xn are sure to be executed is this order.Example: double SL=Ask-25*Point; double TP=Ask+25*Point; int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,SL,TP, My comment,123,0,Red);The comma operation is executed from left to right. A pair of expressions separated by a comma is calculated from left to right with a subsequent deletion of the left expression value. All side effects of left expression calculation can appear before we calculate the right expression. The result type and value coincide with the type and value of the right expression. The result looks like an address if the right expression is an address too.In contexts where the comma has a special purpose, like in the list of actual function parameters or in list of initializers, the comma operation described here cannot appear but in brackets, for example f(a, (t=3,t+2), c);the function contains three parameters, and the second parameters value is 5. Precedence rulesEach group of operations in the table has the same priority. The higher the priority is, the higher is the groups position in the table. The execution order determines the grouping of operations and operands. () Function call From left to right Array element selection ! Negation From left to right Bitwise negation - Sign changing operation * Multiplication From left to right / Division % Module division + Addition From left to right - Subtraction Right shift Less than From left to right Greater than = Greater than or equals = Equals From left to right != Not equal & Bitwise AND operation From left to right Bitwise exclusive OR From left to right | Bitwise OR operation From left to right & Logical AND From left to right | Logical OR From left to right = Assignment From right to left += Assignment addition -= Assignment subtraction *= Assignment multiplication /= Assignment division %= Assignment module = Assignment right shift = x;y向左位移x位 y = x;得到逻辑AND的值 y &= x;得到逻辑OR的值 y |= x;得到逻辑非OR的值 y = x;注:一个表达式只能有一个赋值运算符.关系运算符用返回0(False)或1(True)来表示两个量之间的关系。a是否等于b a = b;a是否不等于b a != b;a是否小于b a b;a是否小于等于b a = b;真假运算符否定运算符(!),用来表示真假的反面的结果。/ 如果a不是真的if(!a)Print(not a);逻辑运算符或(|)用来表示两个表达式只要有一个成立即可。示例:if(xl)Print(out of range);逻辑运算符和(&)用来表示两个表达式要同时成立才行。示例:if(p!=x & py)Print(true);n+;位逻辑运算符 运算符对操作数执行按位求补操作。b = n; 运算符对操作数执行向右位移操作。x = x y; 运算符对操作数执行向左位移操作。x = x y;一元 & 运算符返回操作数的地址为整型和 bool 类型预定义了二进制 & 运算符。对于整型,& 计算操作数的按位“与”。对于 bool 操作数,& 计算操作数的逻辑“与”;也就是说,当且仅当两个操作数均为 true 时,其结果才为 true。b = (x & y) != 0);二进制 | 运算符是为整型和 bool 类型预定义的。对于整型,| 对操作数进行按位“或”运算。对于 bool 操作数,| 对操作数进行逻辑“或”计算,也就是说,当且仅当两个操作数均为 false 时,其结果才为 false。b = x | y;为整型和 bool 类型预定义了 二进制操作数。对于整型, 计算操作数的按位“异或”。对于 bool 操作数, 计算操作数的逻辑“异或”;也就是说,当且仅当只有一个操作数为 true 时,其结果才为 true。b = x y;注:位逻辑运算符只作用于Integers类型其它运算符索引。定位在数组中i位置的值。arrayi = 3;/将3负值到array数组第i位置上使用 x1,x2,.,xn 这样的方法将各种值传送到function中进行运算。示例:double SL=Ask-25*Point;double TP=Ask+25*Point;int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,SL,TP,My comment,123,0,Red);优先级规则下面是从上到下的运算优先
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 非专业的试题及答案
- 主管专业知识试题及答案
- 水暖专业试题及答案解析
- 中职机电专业试题及答案
- 拳击专业试题及答案大全
- 史专业考研试题及答案
- 水利专业基础试题及答案
- 经济专业试题及答案
- 水工专业试题及答案
- 第二单元 成长的时空 达标测试卷(含答案)统编版道德与法治七年级上册
- 成都数字化档案管理办法
- 掘进安全培训课件
- 《中国儿童幽门螺杆菌感染诊治专家共识(2022)》解读
- 第2课《中国人首次进入自己的空间站》练习题2025-2026学年统编版语文八年级上册
- 山西单招考试题库及答案
- n4考试题真题及答案
- 医保网络安全培训
- 水电碳足迹评估方法-洞察及研究
- 《白雪公主》格林童话课件
- 电梯公司维保人员日常管理制度
- 舒曼教学课件
评论
0/150
提交评论