Objectives of this Tutorial are to have students learn the basics of programming, problem solving, and develop programming skills.
In programming, regardless of the type of programming language you are using, there are some concepts or principles that are used in almost all of them, which in a way makes learning or adopting new languages easier.
We'll talk about these basic principles and concepts used in programming in general.
Computer
Computer is a machine capable of enabling different types of automatic processing of information or data processing.
Language
Form of communication.
When we communicate, we need a specific language to express our words.
Example: English, Portuguese, French, Spanish, Arabic, etc.
Programming Logic
Programming logic is the way a computer program, an algorithm, is written.
Computer Programming
Computer programming is defined as telling the computer what to do through a special set of instructions, which are then interpreted by the computer to perform some tasks. These instructions can be specified in one or more programming languages, including (but not limited to) Java, PHP, C and C++, Python.
Programming language
A set of words, symbols, and codes used to write a program is called a program language.
Different programming languages are available for writing different types of programs.
Levels of programming languages
Programming is coding, modeling, simulating or presenting the solution to a problem, representing facts, data or information using predefined rules and semantics, in a computer or any other device for automation.
Programming is the art and science of translating a set of ideas into a program - a list of instructions a computer can follow. The person writing a program is known as a programmer (also an encoder).
The exact form of the instructions depends on the programming language used. Languages range from a very low level such as Machine Language or Assembly Language to a very high level such as Java, Python, etc. Lower level languages are more closely tied to the platform they are targeted at, while Higher level languages abstract an increasing amount of the programmer's platform.
In other words, low-level programming languages represent instructions in a way that more closely resembles the way a computer actually works. Higher-level languages more closely resemble the way the human mind works. Each type is a good fit depending on the specific case.
Difference between Lower level and High level languages
Low level language is far from human
High level language is close to human
languages Low level language provides facility to write programs in Hardware
level High level language does not offer much facility at the hardware level
Deep hardware knowledge is needed to write programs
Deep hardware knowledge is not necessary to write programs
These languages are commonly used to write hardware programs
These languages are usually Used to Write Application ProgramsProgramming
Basic Concepts
Here we will list, some character sets from programming languages, regardless of the programming language, all use pretty much the same characters, some with the same meaning, and also with different meanings.
Programming Language Character Set
Definition: A symbol used when writing a program is called a character.
A character can be:
- Alphabets / Letters (lower az, uppercase AZ)
- Digits (0-9)
- Special symbols
Symbol Name
~ Til
+ plus sign
# hash
_ Underscore
$ dollar sign
{ } brackets
% sign percent
. dot
^ caret
\ backslash
& ampersand
[ ] parenthesis
* Asterisk
: colon
' sign high commas
“ quotation mark
, sign comma
< Less than
| Vertical bar
> Greater than
( ) Parenthesis
= equal or assignment
/ Division
- subtraction
Tokens
Tokens are the smallest or basic units of a programming language.
One or more characters are grouped in sequence to form meaningful words, these significant words are called tokens.
A token is a collection of characters.
Tokens are classified into 5 types, as below:
- Keywords (Keyword)
- Identifiers
- Constants
- Operators
- Special symbols
Keywords (Keyword)
Tokens with predefined meaning in programming language are called keywords (Keyword).
They are reserved for specific purposes in a programming language, and are called reserved words.
There are many keywords supported in a programming language, here are some of them:
auto
if
float
enum
return
void
break
else
char
for
static
default
double
int
count
while
switch
long
Keyword Rules
- Keywords should not be used as variables, function names, array names, etc.
- All keywords must be written in lowercase.
- The meaning of keywords cannot be changed by users.
Identifiers
Identifiers are the names given to program elements, such as variables, constants, function names, array names, etc.
Consists of one or more letters or digits or underscore.
Rules for identifiers
- The first character must be an alphabet or an underscore _
- Then the first character is followed by any number of letters or digits.
- No extra symbols are allowed other than letters, digits and underscores
- Keywords cannot be used as identifiers
- Identifiers are case-sensitive.
Example-1: Area, area, Sum_, sum
Example-2
Identifier | Reasons for invalidity |
angola06 | valid |
_angola | valid |
angola_06 | valid |
angola_06_king | valid |
__angola | valid |
06angola | invalid, as it starts with digits |
int | invalid, as int is a keyword |
angola 06 | is not valid , as there is space between angola and 06 |
angola@06 | invalid, as @ is not allowed |
Constants
Constants refers to fixed values that do not change during program execution.
The different types of constants are:
Integer
constant Real constant / constant of Floating point
Enumeration
character Constant
constant string
Constant integer
Definition: An integer is an integer with no decimal points. No extra characters.
Three types of integer numbers
Decimal numbers: are constants with a combination of digits from 0 to 9, optional + or -
Ex: 123, -345, 0, 5436, +79
Octal integers: are constants with a combination of digits from 0 to 7, but has a prefix of 0
Ex: 027, 0657, 0777645
Hexadecimal integers: digits from 0 to 9 and characters from aaf, it must start with 0X or 0x
Ex: 0X2 0x56 0X5fd 0xbdae
Real constants / floating point:
Floating point constants are base-10 numbers represented by part fractional numbers, such as 10.5. They can be positive or negative.
Two forms are:
Fractional form: A floating-point number represented using the fractional form has an integer part followed by a period and a fractional part.
Ex:
0.0083
215.5
-71.
+0.56 etc.
Exponential form: A floating point number represented using the form Exponent has 3 parts mantissa and exponent
Mantissa is a real number expressed in decimal or integer notation.
Exponent must be integer with + or - optional
Ex 9.86 E 3 => 9.86 * 103
Ex 9.86 E -3 => 9.86 * 10-3
Character constant
A symbol enclosed in a pair of single quotes is called character constant. Each character is associated with a unique value called an ASCII value.
Ex: '9' '$'
Backslash Constants (Escape)
Sequence CharacterAn escape sequence character starts with a backslash and is followed by a character. A backslash along with a character generates special printing effects.
It always starts with a backslash, so they are called as backslash constants.
Character | Meaning |
\a | Beep |
\b | Cursor moves left by one position |
\n | Cursor moves to next line |
\t | Cursor moves right by 8 position |
\r | Cursor moves to beginning of same line |
\ 0 | NULL |
These constants and their meanings can vary depending on the type of programming language you are using, but for the most part the meanings are the same.
String Constant
A string of characters enclosed in a pair of double quotes is called a string constant.
Ex: "9" "SVIT"
Variable
A variable is a name given to the memory location where data can be stored.
The use of variable name data can be stored in a memory location and can be accessed or manipulated very easily.
Rules for variables
The first character must be an alphabet or an underscore _
Then the first character is followed by any number of letters or digits.
No extra symbols are allowed other than letters, digits and underscores
Keywords cannot be used as identifiers
Example:
Sum - valid
For1- valid
for -invalid (is a keyword)
Post a Comment
0Comments