Skip to content

Latest commit

 

History

History
72 lines (43 loc) · 1.42 KB

Unit-03.md

File metadata and controls

72 lines (43 loc) · 1.42 KB

Variables

To create a variable, specify the type and assign it a value. You can also declare a variable without assigning the value, and assign the value later.

Basic Data Types

image

Basic Format Specifiers

image

int

stores integers (whole numbers), without decimals, such as 123 or -123.

// Defining a variable with value
int my_number = 15;
// Defining a variable
int my_number2;
// Assigning the value
my_number2 = 15;

float

stores floating point numbers, with decimals, such as 19.9 or -19.9.

float myFloatNum = 5.1 

float myFloatNum2;
myFloatNum2 = 5.1

double

stores double floating point numbers, with large values after decimals, such as 19.995165 or -19.95165.

double myDoubleNum = 5.1512 

double myDoubleNum2;
myDoubleNum2 = 5.1512

char

stores a single character in the variable with single quotes, such as A or c.

char myChar = 'A'

char myChar2;
myChar2 = 'c'

Constants

const is used to define a variable that cannot be changed after defined.

const int myNum = 15; //This variable cannot be changed after this.

We cannot define a const and assign its value after.