First Exercise
This commit is contained in:
17
Informatik_I/Exercise_1/Task_1/README.md
Normal file
17
Informatik_I/Exercise_1/Task_1/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Task
|
||||
|
||||
Let `a`, `b`, `c`, and `d` be variables of type `int`.
|
||||
|
||||
- Which of the following character sequences are valid expressions in the sense that they are accepted by a C++ Compiler? Explain your answer.
|
||||
|
||||
1. a = b = 5
|
||||
1. 1 = a
|
||||
1. ++a + b++
|
||||
1. a + b = c + d
|
||||
1. a = 2 b
|
||||
|
||||
Assume that all the variables have been defined and correctly initialized and that all expressions are completely independent from each other.
|
||||
|
||||
- For each of the expressions that you have identified as valid, decide whether the entire expression is an `lvalue` or an `rvalue`, and explain your decision.
|
||||
|
||||
- Determine the values of the expressions that you have identified as valid and explain how these values are obtained.
|
23
Informatik_I/Exercise_1/Task_1/main.md
Normal file
23
Informatik_I/Exercise_1/Task_1/main.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Task 1
|
||||
|
||||
---
|
||||
|
||||
### Expression 1: `a = b = 5`
|
||||
|
||||
The expression is valid and will be accepted by the CPP compiler. It will result with the l-values `a = 5` and `b = 5`. This is due to the fact the the `=` opperation is read from right to left so `b = 5` will run first and `a = b` afterwards.
|
||||
|
||||
### Expression 2: `1 = a`
|
||||
|
||||
The expression is invalid.
|
||||
|
||||
### Expression 3: `++a + b++`
|
||||
|
||||
The expression is valid and will be accepted by the CPP compiler. It will result in a r-value since the result is not assigned to a variable.
|
||||
|
||||
### Expression 4: `a + b = c + d`
|
||||
|
||||
The expression is invalid.
|
||||
|
||||
### Expression 5: `a = 2 b`
|
||||
|
||||
The expression is valid and will be accepted by the CPP compiler. It will result with the l-value `a = 2 b`. This is valid since a l-value can be a r-value.
|
Reference in New Issue
Block a user