BP-2-5 Basic Computation of Data - Expressions

Chapter 02 Description of Simple Data

6. Basic Computation of Data - Expressions

6.1 Component of Expression
  • Expression consists of operators, operands and parentheses, which make up the primitive computation unit in a program.

  • Constants and Variables alone make up a special form of expression called primitive expression or atomic expression.

  • If there are two operators live next to each other, to make it not ambiguous, we use whitespace to separate them apart.

6.2 Types of Expression
1. According to Their Return Value
  • Arithmetic Expression evaluates to integer type or real type.
  • Relational/Boolean Expression evaluates to boolean type.
  • Address Expression evaluates to an address.
2. According to Whether its Value is Determined When Compiling
  • Constant Expression’s value is determined when compiling because its value doesn’t need the implementation of the whole program to define.
3. According to Whether it has an Explicit Address in the Memory
  • Lvalue Expression has an address representing a room in the memory to store its value and its addressed can be accessed using &.
    • Lvalue expression can also be divided into modifiable and unmodifiable because a symbolic constant also has its address but its value can’t be modified.
  • Rvalue Expression’s value is stored in temporary store unit whose address can’t be accessed during the program using & and when the expression is evaluated over, the space will be released.
6.3 Precedence and Associativity of an Operator

Each operator has its built-in associativity and precedence.

The precedence defines the priority of two nearby operator while the associativity defines who came first when their are of the same priority.

Basic Rule for Precedence:
  • unary > binary > ternary > assignment

  • arithmetic > bitwise shift > relational > bitwise logic > logic

6.4 Output
#include <iostream>
using namespace std;
int main(){
    ......
    cout << a + b * c;
    cout << a;
    cout << b;
    cout << endl; //another line
    //or
    cout << a + b * c << a << b << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值