MD. Tanjil Hasan
MD. Tanjil Hasan

Reputation: 17

Why is this addition being executed?

Why does this happen?

Why does this program give the correct output?

a = 5 
c = a + b 
b = 5

Output:

c = 10

Upvotes: 0

Views: 45

Answers (1)

m7913d
m7913d

Reputation: 11072

This probably happens because your workspace is not empty at the start of your execution, i.e. b was already defined to be 5 before you executed your code.

If you clear your workspace at the beginning, the program will work as expected and return an Undefined function or variable 'b' error:

clear all;
a = 5 
c = a + b 
b = 5

Upvotes: 1

Related Questions