Académique Documents
Professionnel Documents
Culture Documents
cccdigital.io
Evolution of programming languages
2
cccdigital.io
Evolution of programming languages: Machine Friendly Languages
The programming languages of this era dealt with front panel switches that gave
instructions directly to the processor. The instruction set contained binary set of
0’s and 1’s.
The programmer’s difficulty level in comprehending the same was very high.
However the code ran very fast, was efficient and precise because instructions
directly execute on the processor and hence was machine friendly.
Fixing the errors in the code was almost impossible and the code was purely
machine dependent and would not run on any machine other than for which it
was intended.
3
cccdigital.io
Evolution of programming languages: Assembly Languages
The code in this era was written and read by the coders.
4
cccdigital.io
Evolution of programming languages: High Level Languages
The languages of this era support structured programming. They are machine
independent and programmer friendly.
The languages include ForTran, ALGOL, COBOL C, C++, BASIC, Pascal, Java,
though they are separable based on their characteristics.
The concept of aggregate data types has made this era languages greatly
distinguishable from the era of assembly codes, thus introducing new phrase
called “high level languages”.
5
cccdigital.io
Evolution of programming languages: High Level Languages
While the previous era programming languages like C, C++, Java still sustained
their importance and popularity, languages like Accell/SQL, Cogon’s,
PowerHouse and Audit have evolved with higher support for database
management, report generation, mathematical optimization, User Interface
development etc.
6
cccdigital.io
Program Development Environments
7
cccdigital.io
Introduction to C
cccdigital.io
Introduction to C
Programming is not limited to just one area; it has penetrated into almost all
areas of engineering and sciences, as the versatility of computational devices
is vast.
9
cccdigital.io
Introduction to C
“C” seems a strange name for a programming language but it is one of the
most widely used languages in the world.
Since C and UNIX have evolved hand in hand over the period of time, most
of the C attributes have the flavors of UNIX.
Operating systems of UNIX variant has the support for C code compilation
as an integral part of the operating system.
10
cccdigital.io
Structure of a C Program
11
cccdigital.io
Code execution steps
12
cccdigital.io
Tokens
The smallest part identified by the compiler in the code is called a token. It
may be a single character or a word (sequence of characters) to form a
single part.
Tokens can be classified as keywords, literals, identifiers, operators, etc.
13
cccdigital.io
Keywords
14
cccdigital.io
Constants and Literals
15
cccdigital.io
Data Types
It is used to identify the type of the data. It also specifies the size and range of
the data under a certain type.
16
cccdigital.io
Data Types
17
cccdigital.io
Primitive/Basic Data Types
char: a single byte, capable of holding one character in the local character set
18
cccdigital.io
Qualifiers
In addition, there are a number of qualifiers that can be applied to these
basic types. short and long apply to integers:
(ANSI C compilers give 4 bytes for int, DOS compilers give 2 bytes for int)
19
cccdigital.io
Qualifiers
20
cccdigital.io
Literals
Integer Literals
- decimal ( 123, 1000, 10, etc...)
- octal ( 0123, 01000, 010, etc...)
- hexadecimal (0x12, 0xAB, 0xabc, etc...)
21
cccdigital.io
Representation of a Positive Number
Sign bit:
25 is positive value that’s why sign bit set to zero
Sign bit
22
Representation of a Negative Number
Negative numbers can be Represented in 2’ complement form 2’s
complement of a number is it’s one’s complement + 1 And negative
numbers sign bit set to 1
25 00011001
11100110 (1's Complement of 25)
1
-25 1 1 1 0 0 1 1 1 (2's Complement of 25)
-25 1 1 1 0 0 1 1 1
Sign bit
23
Representation of a Negative Number
24
Representation of a Negative Number
sign bit
In the given pattern sign bit set to 1 therefore it is a representation of a
negative number(2’s complement)
11001101
00110010
+1
00110011 = 51
25
Magic of Number Representation
26
Variables
A variable is a named memory location which can store a value and that value
can be modified subsequently.
Ex: char ch=‘A’;
The variable ch has been declared as char type and it has a value ‘A’. ASCII value of ‘A’ is 65.
Therefore 65 will be stored in binary format in the memory
which has been allocated for variable ch.
int a=100;
The variable a has been declared as integer type and value 100 will be stored
in binary format in the memory which has been allocated for variable a.
27
Expressions
1. Arithmetic expressions
2. Relational expressions
3. Logical expressions
4. Conditional expressions
28
OPERATORS
• The symbols which are used to perform logical and mathematical operations
in a C program are called C operators.
29
OPERATORS
• Special operators
• Logical operators
30
Arithmetic Expressions:
* / % Multiplication/Division/Modulo
+- Addition/Subtraction
5. 1 will be subtracted form the Result in step 4 i.e 6-1 and final result is 5
31
Arithmetic operators
int main() {
int num1,num2;
scanf(“%d%d”,&num1,&num2);
printf(“\nAddition is%d”,num1+num2);
printf(“\nSubtraction is %d”,num1-num2);
printf(“\nMultiplication is %d”,num1*num2);
printf(“\nQuotient is %d”,num1/num2);
printf(“\nRemainder is %d”,num1%num2);
return 0;
32
Assignment operators
Assignment operator can be used to assign the simplified value of right hand
side expression to left side variable.
Ex:
int a=10, b=20;
int c=a+b;//addition of a and b can be assigned to c
= Assignment Operator
Composite Assignments:
*= /= %= Mulplication/division/modulo assignment
+= -= Addition/Subtraction assignment
&= |= ^= <<= >>= Bitwise assignment
Composite assignment ex:
int a = 10;
a += 5;//This is equal to a=a+5.
33
Relational operators
Relational operators can be used to get the relation between two
operands. Usually these are used to form conditions.
The result of the relational expression can be either zero or non-zero value. Here, the zero
value is equivalent to a false and non-zero value is equivalent to true.
34
Logical operators
Logical operators are used to form compound conditions by adding two or
more conditions.
&& Logical AND
|| Logical OR
! Logical NOT
35
Logical operators
Logical OR (||):
if( a>b | | a<c ) {statements; }
here two conditions are combined to form a compound condition. If both
conditions are false then only the compound condition is also false.
If the first condition is true the compiler will not evaluate the second
condition.
36
Bitwise Operators:
Bitwise OR : |
Bitwise XOR : ^
37
Bitwise AND (&)
cccdigital.io
38
Bitwise AND (&)
#include <stdio.h>
int main()
{
printf("%d\n",(0&0)); //gives 0
printf("%d\n",(0&1)); //gives 0
printf("%d\n",(1&0)); //gives 0
printf("%d\n",(1&1)); //gives 1
return 0
cccdigital.io
39
Bitwise AND (&)
#include <stdio.h>
int main()
{
int a=112, b=17;
int c;
c=a&b;
printf(“\nBitwise and is %d “,c);
return 0;
}
Output: 16
Binary representation of 1 1 2 is 01110000
Binary representation of 17 is 00010001
a&b = 106 & 15 is 00010000 = 16
cccdigital.io
40
Bitwise OR (|)
cccdigital.io
41
Bitwise OR (|)
#include <stdio.h>
int main()
{
printf("%d\n",(0|0)); //gives 0
printf("%d\n",(0|1)); //gives 1
printf("%d\n",(1|0)); //gives 1
printf("%d\n",(1|1)); //gives 1
return 0;
cccdigital.io
42
Bitwise OR (|)
#include <stdio.h>
int main()
{
int a=112, b=17;
int c;
c=a|b;
printf(“\nBitwise and is %d “,c);
return 0;
}
Output: 113
Binary representation of 112 is 01110000
Binary representation of 17 is 00010001
a| b = 106 | 15 is 01110001 = 113
cccdigital.io
43
Bitwise eXclusive OR (^)
cccdigital.io
44
Bitwise eXclusive OR (^)
#include <stdio.h>
int main()
{
printf("%d\n",(0^0)); //gives 0
printf("%d\n",(0^1)); //gives 1
printf("%d\n",(1^0)); //gives 1
printf("%d\n",(1^1)); //gives 0
return 0;
cccdigital.io
45
Bitwise eXclusive OR - XOR(^)
#include <stdio.h>
int main()
{
int a=112, b=17;
int c;
c=a^b;
printf(“\nBitwise and is %d “,c);
return 0;
}
Output: 97
Binary representation of 112 is 01110000
Binary representation of 17 is 00010001
a^b = 1 1 2 ^ 17 is 01100001 = 97
cccdigital.io
46
Bitwise one’s Complement
#include<stdio.h> If ~ n = -(n+1)
int main()
{
printf("%d",~25); Then
}
~ 72 = ?
Ourput : -26 ~ -72 = ?
cccdigital.io
47
Conditional operator (ternary operator) ?:
#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
int a,b; int a,b;
scanf(“%d%d”,&a,&b); scanf(“%d%d”,&a,&b);
if(a>b){ printf(“a is big); } (a>b)?printf(“a is big):printf(“b is big”);
else{ printf(“b is big”); } return 0;
return 0; }
}
48
Increment/decrement operators
49
Pre increment vs Post increment:
Ex: int a=10, b;
b=a++;
int a = 10, b;
b = ++a;
50
Pre decrement vs Post decrement:
Ex : int a = 10, b;
b = a--;
int a=10,b;
b=--a;
a = a-1;
b = a;
i.e. a = 9, b = 9;
51
Special operators
& ➔ gives address of a variable
* ➔ Acts as a re directional operator
sizeof( )➔ operator used to get size of a specific variable
; ➔ every statement in c program ends with semi colon
, ➔ two or more expressions can be separated by comma
. ➔ Members of structures and unions can be accessed using dot
: ➔ is used switch statement and ternary operator
() ➔ are mentioned as function calling
[] ➔ are for array indexing
{} ➔ are for block opening and closing
52