Basic Programming Constructs
Basic Programming Constructs
CONSTRUCTS
WHAT IS A VARIABLE?
VARIABLE
•Programmer-defined word that
holds the value of the user.
•Saves a part of memory to store a
determined value.
RULES IN DECLARING
VARIABLES:
•Must begin with a letter or underscore
(_), then followed by a letter, digit, or
underscore.
•It must not include blanks
RULES IN DECLARING
VARIABLES:
•It must not be the keywords but reserved
words by the language.
•It must not be given a name with the
same name as other functions.
WHAT IS A CONSTANT?
CONSTANT
•Have fixed value that cannot be
changed at runtime.
•To declare a constant, type const
CHARACTER CONSTANTS
•\n– New line
•\t– Horizontal Tab
•\b– Backspace
CHARACTER CONSTANTS
•\a– Alert or beep
• \’– Single quote
•\\– Backslash
WHAT IS A
LITERAL?
LITERALS
•They are the values within the
source code of a program
•Literal Constants
• Can be integer numerals, floating
point numerals, characters,
strings, or Boolean values.
INTEGER LITERALS
•They are constants and also
called decimal numerals.
• Examples:
• 235
• 67
• 91
FLOATING POINT LITERALS
•Numbers with decimal, fractions,
and exponents.
• Examples:
• 3.14159
• 6.02e23 // 6.02*10^23
CHARACTER AND STRING
LITERALS
•Non-numeric and string literals
• Examples:
• ‘j’ – character
• “CheriBerry” - String
BOOLEAN LITERALS
•Its either TRUE OR FALSE
VARIABLE DECLARATION
Write V if the variable is valid or IV if it
is not.
1. Jasmin Almarinez
2. 1st
3. First
4. cin
5. abc
6. 1person
7. One
8. _Cheriberry
9. @Grade10
10. Jasmine_
WHAT IS A
DATA TYPE?
DATA TYPE
•Value types and reference types
•Variables should be identified on
what data type it can hold or
included.
CATEGORIES OF DATA TYPE
•Value type – holds the data
within its own memory location
•Reference Type – contains a
pointer to another memory
location that holds the data.
• Examples:
• int ‘i’ = 42;
• char ch = ‘A’;
• bool result =true;
• string str = “Hello”;
• byte[] bytes = {1, 2, 3} ; Reference type
VALUE TYPES
REFERENCE TYPES
REFERENCE DESCRIPTION SIZE
TYPES
Object Base type of all 8+ bytes
types