Introduction To Programming Fundamentals
Introduction To Programming Fundamentals
Language:-
- Way of communication
- Should be Common Medium between two persons for communications
Language of Computer / Machine Language / Binary Language:-
- Computer is an electronic machine which can take inputs, process it and produces outputs
- Language of computer is the sequence of zeros and ones
Think, if we people want to communicate with computer, it will be very difficult for us to learn the language of zeros and
ones. Therefore, we need a Translator for communication with computer.
Translator (Software) :- watmytu +
1. Compiler
2. Interpreter
3. Assembler
NOTE:- To work on a computer in a particular language, we need two type of software :-
a) Editor of that particular language for writing source code.
b) Translator of that particular language
Programming Fundamentals
Compiler:- object code / machine code
- As a whole (just like a briefing in press conference)
- Source code converts completely into machine code / machine language / object code
- Execution Fast
- If there exists any error, it will never executes your program
- With object code, program may be executed again and again without translating it each time.
- High level languages first converts into machine code, then executes
- C and C++ use compiler
Interpreter:-
- Step by step / instruction by instruction ( just like translator in meeting )
- Execution slow
- It executes the program until it finds the error in the instruction (stop execution then)
- Each time translation is required for execution
Assembler:-
- Used in Assembly Language
Programming Fundamentals
Program:-
- Set of instructions which solve a user specific problem
Instruction:-
- Statements / Executable expressions
- Statement causes the computer to carry out some action
1. Expression Statements
- Expression followed by a semicolon ; e.g. A =5; or c=a+b ; or x= 5+2 ;
2. Control Statements
- Are used to create special program features such as logical tests / loops etc.
- Other statements may be imbedded in control statements
3. Compound Statements
- Consists of several individual statements enclosed within a pair of braces { } Block of statements
- It may contain expression statements, control statements or compound statements
- Does not end with semicolon after braces
Programming Fundamentals
Expression:-
- Combination of operands and operators
Operands:- ( VARIABLES or CONSTANTS … ?)
- Basic symbols which receive some action. 5 + 3; x+y; 14 / 5.5 ;
Operators:-
- Symbols which can perform some operation. For example + , -, *, / etc 5+ 3
1. Arithmetic Operators
- Unary operators: 1) Unary minus - 2) Postfix a) Increment ++ b) Decrement -- 3) Prefix a) Increment ++ b) Decrement --
- Binary operators: 1) * 2) / 3) % modulus / remainder
- 4) + 5) -
2. Relational Operators / Comparison / true or false
- 1) < 2) <= 3) > 4) >=
- (Equality operators) 5) == 6) !=
4. Assignment Operators
- 1) = x = 5+9+7 ;
- 2) += 3) -= 4) *= 5) /= 6) %= x += 5 ; x = x+5;
Programming Fundamentals
Rule of Precedence:-
The order of evaluation of operators
- 3 + 4*5 (Answer: ?) 3 + 20 23
- 6 / 10 * 5 (Answer: ?) 15 - 13 / 5 (Answer: ?) 3 + 4 / 5 ( Answer: ?)
- 6 + 4 * 5 *(2+3) (Answer: ?)
- 6 + 4 * 5 / (2+3) + 10 (Answer: ?)
- etc
Associativity:-
The evaluation order of operators having same precedence (either from left to right OR from
right to left)
- 30 / 2 * 3 – 5 + 10 (Answer: ?)
- 10 + 10 * 3 / 3 – 5 (Answer: ?)
- etc
-Prefix, assignment (right to left ?)
Programming Fundamentals
Set of C++ Characters:-
-ABC…Z (A to Z upper case: 26)
- abc … z ( a to z lower case:26)
-012…9 ( 0 to 9 digits :10)
- Special characters (+ - blank spaces … etc : ?)
Note: how many number of C++ characters….? Must visit ( http://aboutc.weebly.com/c-character-set.html )
4. Assignment Operators
- 1) = x = 5+9+7 ;
- 2) += 3) -= 4) *= 5) /= 6) %= x += 5 ; x = x+5;
Programming Fundamentals
Constant:-
-A quantity that cannot change its value during program execution
- Two types of constants in C++ A) Literal Constant B) Symbolic Constant
A) Literal Constant: Literal Constant is a value that is typed directly in a program where it is needed
1) Integer Constants:
i. Numeric values without decimal point / fraction : (… -3, -2, -1, 0, 1, 2, 3…)
ii. Both positive and negative integer constant may be used in the program
iii. negative sign will be used for negative integers and no sign will be used for positive integers (by default value is positive)
iv. For example: 50, 30, -20, -10, 65000L. (L at the end of integer indicates that it is a long integer)
2) Floating Point Constants / Real Constant:
i. Numeric values with decimal point or fraction : ( 234.56, 20.45, 4.5, … -4.5, -20.89, … )
ii. A real constant is combination of a whole number followed by a decimal point and the fractional part. Example: 0.0083, -0.75, 0.95 etc
iii. Both positive and negative floating point constants may be used in the program
iv. negative sign will be used for negative floating point and no sign will be used then value is positive by default
v. For example: 10.45 , 56.78, …, 50.89F, 43.12f, …, 34.56L, 88.99L, … (use of F or f at the end, indicates that the value is float. L at the end indicates that the value is long
double. No F or L at the end indicates that the value is double)
vi. The Real or Floating-point constants can be written in two forms: (see next slide)
1. The mantissa part and the exponential part should be separated by letter in exponential form
2. The mantissa part may have a positive or negative sign.
3. Default sign of mantissa part is positive.
4. The exponent part must have at least one digit, which must be a positive or negative integer. Default sign is positive.
5. Range of real constants expressed in exponential for is -3.4e38 to 3.4e38.
Programming Fundamentals : Constant /Symbolic Constant
B) Symbolic Constant:
-A symbolic constant is a NAME given to a value that cannot be changed
-It must be initialized. After initialization, its vale cannot be changed
-Symbolic constant is used to represent a value that is frequently used in a program
-Symbolic constants can be declared in two ways:
1) const Qualifier
1) “const” qualifier is used to define a constant
2) The constant is declared by specifying its name and data type
3) The constant must be initialized with some value
4) The initialized value cannot be changed during program execution
5) Syntax: const data_type Identifier = value ;
• const ketword used to define the constant
• data_type indicates the data type of the constant
• Identifier represent the name of constant
• = assignment operator
• Value represent the value with which constant has been initialized
• Example: const int X = 555; // defines a constant X that is initialized with a value (555) and this value (555) cannot be changed during program execution.
2) define Directive:
1) “define” directive is also used to define a constant
2) Difference between const qualifier and define directive is that define directive does not specify the data type of the constant.
3) “define” directive starts with #
4) It is not terminated with semicolon
5) Syntax: #define Identifier value
• # indicates the start of preprocessor directives
• defineused to define a constant
• Identifier name of the constant
• value represent the value associated with identifier
• Example: #define PI 3.141593 // the preprocessor directive will replace all the occurrences of the identifier with the value in the program
Programming Fundamentals: Constant
Data type:-
-Data type are used for declaring variables or functions of different type
- Data type determines that:-
1) how much space a variable occupies in RAM ( means that how many bytes will be reserved in RAM to form a memory location / a
memory location may be comprised of one or more bytes in RAM). Every data type requires a different amount of memory.
2) which type of value will be stored in this memory location