PHP

In PHP, there is no need to declare variables as you would in C# or C++. Variables are declared when first used. For example, the statement

$number1 = 0;

declares the variable $number1 and initializes it to 0.

Notice: In PHP, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.

Java

Java is a strongly typed programming language. This means that each variable must have a specific data type associated with it. For example, a variable can hold an integer, a real, or a character. In Java there are eight primitive data types: byte, short, int, long, float, double, boolean, or char. Which one to use depends on the given problem! To be more specific:

  • type byte can hold an integer between –127 and +128
  • type short can hold an integer between –32768 and +32767
  • type int can hold an integer between –231 and +231 – 1
  • type long can hold an integer between –263 and +263 – 1
  • type float can hold a real of single precision
  • type double can hold a real of double precision
  • type boolean can hold only two possible values: that is, true or false
  • type char can hold a single character.

In many computer languages, there is one more variable type called “String”, which can hold a sequence of characters. These sequences of characters, or “Strings” are usually enclosed in double or single quotes, such as “Hello Zeus”, “I am 25 years old”, and so on. Java also supports strings, but keep in mind that a string in Java is not a primitive data type. Without going into detail, a string in Java is declared the same way as you declare a primitive data type such as int, long or boolean, but internally Java stores and handles them in a quite different way.

To declare a variable, the general form of the Java statement is

type name [ = value];

where

  • type can be byte, short, int, long, float, double, boolean, char, or even String
  • name is a valid variable name
  • value can be any valid initial value

Below are some examples of how to declare variables.

int number1;
boolean found;
String first_name;
String student_name;

Notice: Please note that “type” String is written with a capital “S”.

Notice: Please note that Java requires that all statements be terminated with a semicolon ( ; ).

In Java you can declare and directly assign an initial value to a variable. The next code fragment

int num = 5;
String name = "Hera";
char favorite_character = 'w';

is equivalent to

int num;
String name;
char favorite_character;
num = 5;
name = "Hera";
favorite_character = 'w';

Notice: In Java, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.

Notice: Please note that in Java  you assign a value to a variable of type String using double quotes (”  “), but you assign a value to a variable of type char using single quotes (‘  ‘).

Last but not least, you can declare many variables of the same type on one line by separating them with commas.

int a, b;
double x, y, z;
long w = 3, u = 2;

C++

C++ is a strongly typed programming language. This means that each variable must have a specific data type associated with it. For example, a variable can hold an integer, a real, or a character. In C++ some of the primitive data types are: bool, int, float, double, and char. Which one to use depends on the given problem! Moreover, several of the basic types can be modified using one or more of these type modifiers:

  • unsigned
  • short
  • long

To be more specific:

  • type bool can hold only two possible values: that is, true or false
  • type int can hold an integer between –231 and +231 – 1
  • type unsigned int can hold an integer between 0 and +232 – 1
  • type short int can hold an integer between –215 and +215 – 1
  • type unsigned short int can hold an integer between 0 and +216 – 1
  • type float can hold a real of single precision
  • type double can hold a real of double precision
  • type char can hold a single character.

In many computer languages, there is one more variable type called “string”, which can hold a sequence of characters. These sequences of characters, or “strings” are usually enclosed in double or single quotes, such as “Hello Zeus”, “I am 25 years old”, and so on. C++ also supports strings, but keep in mind that a string in C++ is not a primitive data type. Without going into detail, a string in C++ is declared the same way as you declare a primitive data type such as int, byte, or double, but internally C++ stores and handles them in a quite different way.

To declare a variable, the general form of the C++ statement is

type name [ = value];

where

  • type can be bool, int, short int, unsigned short int, string and so on
  • name is a valid variable name
  • value can be any valid initial value

Below are some examples of how to declare variables.

int number1;
bool found;
string first_name;
string student_name;

Notice: Please note that C++ requires that all statements be terminated with a semicolon ( ; ).

In C++ you can declare and directly assign an initial value to a variable. The next code fragment

int num = 5;
string name = "Hera";
char favorite_character = 'w';

is equivalent to

int num;
string name;
char favorite_character;
num = 5;
name = "Hera";
favorite_character = 'w';

Notice: In C++, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.

Notice: Please note that in C++  you assign a value to a variable of type string using double quotes (”  “), but you assign a value to a variable  of type char using single quotes (‘  ‘).

Last but not least, you can declare many variables of the same type on one line by separating them with commas.

double x, y, z;
long int w = 3, u = 2;

C#

C# is a strongly typed programming language. This means that each variable must have a specific data type associated with it. For example, a variable can hold an integer, a real, or a character. In C# some of the primitive data types are: bool, int, float, double, decimal, and char. Which one to use depends on the given problem! To be more specific:

  • type bool can hold only two possible values: that is, true or false
  • type byte can hold an unsigned integer between 0 and 255
  • type sbyte can hold a signed integer between -128 and +127.
  • type ushort can hold an unsigned integer between 0 and +65535.
  • type short can hold a signed integer between -32768 and +32767
  • type uint can hold an unsigned integer between 0 and +232 – 1.
  • type int can hold a signed integer between -231 and +231 – 1
  • type ulong can hold an unsigned integer between 0 and +264 – 1.
  • type long can hold a signed integer between -263 and +263 – 1
  • type float can hold a signed real of single precision
  • type double can hold a signed real of double precision
  • type decimal can hold a signed real of high precision (with 28-29 significant digits)
  • type char can hold a single character.

In many computer languages, there is one more variable type called “string”, which can hold a sequence of characters. These sequences of characters, or “strings” are usually enclosed in double or single quotes, such as “Hello Zeus”, “I am 25 years old”, and so on. C# also supports strings, but keep in mind that a string in C# is not a primitive data type. Without going into detail, a string in C# is declared the same way as you declare a primitive data type such as int, byte, or double, but internally C# stores and handles them in a quite different way.

To declare a variable, the general form of the C# statement is

type name [ = value ];

where

  • type can be bool, byte, short, int, string and so on
  • name is a valid variable name
  • value can be any valid initial value

Below are some examples of how to declare variables.

int number1;
bool found;
string first_name;
string student_name;

Notice: Please note that C# requires that all statements be terminated with a semicolon ( ; ).

In C# you can declare and directly assign an initial value to a variable. The next code fragment

int num = 5;
string name = "Hera";
char favorite_character = 'w';

is equivalent to

int num;
string name;
char favorite_character;
num = 5;
name = "Hera";
favorite_character = 'w';

Notice: In C#, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.

Notice: Please note that in C#  you assign a value to a variable of type string using double quotes (”  “), but you assign a value to a variable of type char using single quotes (‘  ‘).

Last but not least, you can declare many variables of the same type on one line by separating them with commas.

int a, b;
double x, y, z;
long w = 3, u = 2;

Visual Basic

Visual Basic is a strongly typed programming language. This means that each variable must have a specific data type associated with it. For example, a variable can hold an integer, a real, or a character. In Visual Basic some of the primitive data types are: Boolean, Integer, Float, Double, Decimal, and Char. Which one to use depends on the given problem! To be more specific:

  • type Boolean can hold only two possible values: that is, True or False
  • type Byte can hold an unsigned integer between 0 and 255
  • type SByte can hold a signed integer between -128 and +127.
  • type UShort can hold an unsigned integer between 0 and +65535.
  • type Short can hold a signed integer between -32768 and +32767
  • type UInteger can hold an unsigned integer between 0 and +232 – 1.
  • type Integer can hold a signed integer between -231 and +231 – 1
  • type ULong can hold an unsigned integer between 0 and +264 – 1.
  • type Long can hold a signed integer between -263 and +263 – 1
  • type Single can hold a signed real of single precision
  • type Double can hold a signed real of double precision
  • type Decimal can hold a signed real of high precision (with 28-29 significant digits)
  • type Char can hold a single character.

In many computer languages, there is one more variable type called “String”, which can hold a sequence of characters. These sequences of characters, or “strings” are usually enclosed in double quotes, such as “Hello Zeus”, “I am 25 years old”, and so on. Visual Basic also supports strings, but keep in mind that a string in Visual Basic is not a primitive data type. Without going into detail, a string in Visual Basic is declared the same way as you declare a primitive data type such as Integer, Byte, or Double, but internally Visual Basic stores and handles them in a quite different way.

To declare a variable, the general form of the Visual Basic statement is

Dim name As type [ = value ]

where

  • type can be Boolean, Byte, Short, Integer, String and so on
  • name is a valid variable name
  • value can be any valid initial value

Below are some examples of how to declare variables.

Dim number1 As Integer
Dim found As Boolean
Dim first_name As String
Dim student_name As String

In Visual Basic you can declare and directly assign an initial value to a variable. The next code fragment

Dim num As Integer = 5
Dim name As String = "Hera"
Dim favorite_character As Char = "w"

is equivalent to

Dim num As Integer
Dim name As String
Dim favorite_character As Char
num = 5
name = "Hera"
favorite_character = "w"

Notice: In Visual Basic, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.

Notice: Please note that in Visual Basic  you assign a value to a variable of type String or Char using double quotes (”  “).

Last but not least, you can declare many variables of the same type on one line by separating them with commas.

Dim a, b As Integer
Dim x, y, z As Double

Python

In Python, there is no need to declare variables as you would in C# or C++. Variables are declared when first used. For example, the statement

number1 = 0

declares the variable number1 and initializes it to 0.

Notice: In Python, you can represent the action of assigning a value to a variable by using the equals ( = ) sign. This is equivalent to the left arrow in flowcharts.