What is the output of the following code? [code]syms x; if(x>50) fprintf('Error') end[/code]

What is the output of the following code?
Code:
syms x;
if(x>50)
fprintf('Error')
end
A. Error
B. Prints Error
C. Does not print error
D. Cannot be determined
 
Answer: a
Explanation: We have declared x as a symbolic variable and haven’t assigned any value to it. So it is not declared with 0, it is only a symbolic character. Hence, the if structure cannot check the condition because it cannot convert the symbolic form to logical form. Hence it won’t go inside the if structure- it will return an error but not print ‘Error’.
 

Tìm kiếm

Back
Top