So, you've mastered the Hello World! program and you want to move forward? Excellent. Let's talk about storing and manipulating Data.
A variable holds information, numbers, words: data. It gives the programmer the ability to store, manipulate, retrieve, and output information.
Some programming languages are "Typed" languages. They have a specific kind of variable, depending on what you want to do. This is important because different types of variables require different amounts of memory (RAM) in the computer. C++ and Java are strongly (or statically) typed languages.
Here are a few variable types, the amount of memory they require, and their limitations:
When creating a variable in strongly typed languages, the programmer needs to know exactly what the variable will be holding. The micro-management of memory and data types is what makes C++ such a strong language for things like video games.
There are three different keywords, each with a special meaning:
// can hold all sorts of data and is globally scoped (more on scope later)
// can hold all sorts of data and is locally or block scoped
// can hold all sorts of data but that data cannot change (or shouldn't, at least)
For this course, it would be best if we use let as often as possible.
Python is a dynamically typed language. You don't even need to put a declaration at all before a variable. You can simply give a new variable name and Python will open memory for it.
a =123# integer
b = 123L # long integer
pi =3.14# double float
myString ="hello"# string
myList =[0,1,2]# list
myTuple =(0,1,2)# tuple
myFile =open(‘hello.py’, ‘r’)# file
C++ is a very strongly or statically typed language. It even has something called pointers which point to (reference) an area in memory instead of a value. Kind of like pointing to your locker instead of seeing what is in your locker.
int* myPointer;// A pointer to an int
bool theSkyIsBlue =true;// You can initialize variables as you declare them
Java is a bit different than C++ in that it has a String variable (array of chars).
A String is more than just a variable - it is something called an Object. You'll see in the code above, there are two ways to declare a String. That's because there is something called a Heap in Java. More on that in Grade 12!