Want to create interactive content? It’s easy in Genially!
COMPUTER 10- VARIABLES
kai casabar
Created on April 11, 2022
Start designing with a free template
Discover more than 1500 professional designs like these:
View
Essential Learning Unit
View
Akihabara Learning Unit
View
Genial learning unit
View
History Learning Unit
View
Primary Unit Plan
View
Vibrant Learning Unit
View
Art learning unit
Transcript
VARIABLES
LESSON 2
COMPUTER PROGRAMMING
LESSON 2
OBJECTCIVE
Create and name Variables
Understand data types used in programming
assign values to variables
Declare and intitialize variables
Computer Programming: VARIABLES
This is any NAME used to hold information or serve as a reference to information
the represented information can change but the operations on the variable remain the same.
VARIABLES
it provides us with names that are used as storage for values that our programs can manipulate.
Subject
TYPES OF VARIABLES
start >
INT
BYTE
SHORT
THIS IS A 16 BIT SIGNED TWO COMPLIMENT INTEGER.
THIS IS A 32 BIT SIGNED TWO COMPLIMENT INTEGER.
IS AN 8-BIT SIGNED TWO'S COMPLEMENT INTEGER.
stores integers (whole numbers), without decimals, such as 123 or -123
IT IS USEFUL FOR SAVING MEMORY IN LARGE ARRAYS, WHERE THE MEMORY SAVINGS ACTUALLY MATTER.
YOU CAN USE A SHORT TO SAVE MEMORY IN LARGED ARRAYS, IN THE SITUATION WHERE THE MEMORY SAVINGS ACTUALLY MATTER.
THIS IS A 32 BIT SIGNED TWO COMPLIMENT INTEGER.THIS DAT TYPE IS GENERALLY THE DEFAULT CHOICE UNLESS THERE IS A REASON.
THEY CAN ALSO BE USED IN PLACE OF INT WHERE THEIR LIMITS HELP TO CLARIFY YOUR CODE; THE FACT THAT THE VARIABLE'S RANGE ARE LIMITED IT CAN SERVE AS A FORM OF DOCUMENTATION.
THIS DATA TYPE WILL MOST LIKELY BE LARGE ENOUGH FOR THE NUMBERS YOUR PROGRAM WILL USE.
DOUBLE
LONG
FLOAT
THIS TYPE IS A SINGLE- PRECISION 32- BIT IEEE 754 FLOATING POINT.
IS AN 64-BIT SIGNED TWO'S COMPLEMENT INTEGER.
THIS TYPE IS A DOUBLE - PRECISION 64- BIT IEEE 754 FLOATING POINT.
IF YOU NEED TO SAVE MEMORY IN LARGE ARRAYS OF FLOATING POINT NUMBERS . THIS DATA TYPE SHOULD NEVER BE USED FOR PRECISE VALUES, SUCH AS CURRENCY.
USE THIS DATA TYPE WHEN YOU NEED A RANGE OF VALUES WIDER THAN THOSE PROVIDED BY INT.
FOR DECIMAL VALUES, THIS DATA TYPE IS GENERALLY THE DEFAULT CHOICE. THIS DATA TYPE SHOULD NEVER BE USED FOR PRECISE VALUES, SUCH AS CURRENCY
CHAR
BOOL
THIS DATA TYPE IS A SINGLE- 16- BIT UNICODE CHARACTER
STORES VALUES WITH 2-STATEMENTS; TRUE OR FALSE
stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
USE THIS DATA TYPE FOR SIMPLE FLAGS THAT TRACK CONDITIONS.
THIS DATA TYPE REPRESENTS ONE BIT OF INFORMATION, BUT ITS "SIZE" IST SOMETHING THAT'S PRECISELY DEFINE.
Declaring (Creating) Variables
To create a variable, specify the type and assign it a value:
Where type is one of C types (such as int), and variableName is the name of the variable (such as x or myName). The equal sign is used to assign a value to the variable and the value is the value it self.
EXAMPLE
Create a variable called myNum of type int and assign the value 15 to it: int myNum = 5;
VARIABLES
SCOPE OF VARIABLES
A SCOPE is a region of the program where variables can be decclared.
GLOBAL VARIABLES- Whe the variable is written outside of all the funtion.
LOCAL VARIABLES- Whe the variable is written inside the funtion box.
INSTRUCTIONS
LOCAL VARIABLES
GLOBAL VARIABLES
VARIABLES
ASSIGNING VALUES TO VARIABLES
In assigning the variables, we use the equa l sign = (assignment operator
syntax: type variableName = value ; int letter = A ;
Let’s keeplearning!
We will continue learning