variable and its declaration

variable and its declaration - Variables and declarations A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Variables and declarations A variable is a name with an associated value. Throughout this course, we draw a variable as a named box with the value in the box. For example, here is a variable x associated with the value 5. Sometimes, we draw a line instead of a box, as shown to the right below: Java is strongly typed , meaning that it has properties like the following. 1. Each variable must have a type . When we want to make the type of a vari- able explicit, we put the type to the right of the box. 2. Only values of that type may be associated with the variable . So, variable x, declared above, cannot contain a boolean value true or false . 3. Each expression has a type, which depends on the types of its operands, and 4. An operation can be applied only to operands of the appropriate type. For example, an int variable may contain only an int value. A boolean variable may contain only a boolean value, and so on. Also, operation is legal only if b and c are of type boolean . Matlab is not strongly typed —one second, a variable may contain a complex number, the next second, an
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

variable and its declaration - Variables and declarations A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online