After the execution of above statement the value of the variable
float mBallX; //declares mBallX to be of type float
mBallX = 0; //assigns a value of 0 to mBallX
mBallXwill be 0. That is, the assignment operator has assigned a value of 0 to
mBallX. In order to assign a value of
mBallX, you simply need to change the value that comes after the operator.
When you assign a value it’s important to check that it fits within the range the data type accepts. For example, the
mBallX = 100;
bytedata type can only hold values with a minimum value of -128 and a maximum value of 127, so you are not able assign a value of 345 or -6892 to a variable of this data type. You can check which data type is most appropriate for a particular use in Step 2.4.
Begin Programming: Build Your First Mobile Game
Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.