the assignment statement - The assignment statement The...

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

View Full Document Right Arrow Icon
The assignment statement The assignment statement is used to store a value in a variable. As in most programming languages these days, the assignment statement has the form: < variable >= < expression >; For example, once we have an int variable j , we can assign it the value of expression 4 + 6 : int j; j= 4+6; As a convention, we always place a blank after the = sign but not before it. You don’t have to follow this convention. Our reasons for it are explained on p. 27 of Gries/Gries. Once we have variables with values, we can use those variables in expressions. For example, we can evalu- ate the expression consisting simply of j , or the expression 2*j , and we can store the value of expression j+1 in another variable k: j 2*j int k; k= j + 1; k You must memorize how the assignment statement is executed, or carried out. If asked, you should say: Evaluate the < expression > and store its value in the < variable >. Please memorize this definition of how to execute the assignment statement. In order to be sure that you under-
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

the assignment statement - The assignment statement The...

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