SlideShare a Scribd company logo
1
Tokens in CTokens in C
Keywords
These are reserved words of the C language. For example int,
float, if, else, for, while etc.
Identifiers
An Identifier is a sequence of letters and digits, but must start with a
letter. Underscore ( _ ) is treated as a letter. Identifiers are case sensitive.
Identifiers are used to name variables, functions etc.
Valid: Root, _getchar, __sin, x1, x2, x3, x_1, If
Invalid: 324, short, price$, My Name
Constants
Constants like 13, ‘a’, 1.3e-5 etc.
2
Tokens in CTokens in C
String Literals
A sequence of characters enclosed in double quotes as “…”. For
example “13” is a string literal and not number 13. ‘a’ and “a” are
different.
Operators
Arithmetic operators like +, -, *, / ,% etc.
Logical operators like ||, &&, ! etc. and so on.
White Spaces
Spaces, new lines, tabs, comments ( A sequence of characters enclosed
in /* and */ ) etc. These are used to separate the adjacent identifiers,
kewords and constants.
3
Basic Data TypesBasic Data Types
Integral Types
Integers are stored in various sizes. They can be signed or unsigned.
Example
Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign
bit. If the sign bit is 0, the number is treated as positive.
Bit pattern 01001011 = 75 (decimal).
The largest positive number is 01111111 = 27
– 1 = 127.
Negative numbers are stored as two’s complement or as one’s
complement.
-75 = 10110100 (one’s complement).
-75 = 10110101 (two’s complement).
4
Basic Data TypesBasic Data Types
Integral Types
char Stored as 8 bits. Unsigned 0 to 255.
Signed -128 to 127.
short int Stored as 16 bits. Unsigned 0 to 65535.
Signed -32768 to 32767.
int Same as either short or long int.
long int Stored as 32 bits. Unsigned 0 to 4294967295.
Signed -2147483648 to 2147483647
5
Basic Data TypesBasic Data Types
Floating Point Numbers
Floating point numbers are rational numbers. Always signed numbers.
float Approximate precision of 6 decimal digits .
• Typically stored in 4 bytes with 24 bits of signed mantissa and 8 bits
of signed exponent.
double Approximate precision of 14 decimal digits.
• Typically stored in 8 bytes with 56 bits of signed mantissa and 8 bits
of signed exponent.
One should check the file limits.h to what is implemented on a particular
machine.
6
ConstantsConstants
Numerical Constants
Constants like 12, 253 are stored as int type. No decimal point.
12L or 12l are stored as long int.
12U or 12u are stored as unsigned int.
12UL or 12ul are stored as unsigned long int.
Numbers with a decimal point (12.34) are stored as double.
Numbers with exponent (12e-3 = 12 x 10-3
) are stored as double.
12.34f or 1.234e1f are stored as float.
These are not valid constants:
25,000 7.1e 4 $200 2.3e-3.4 etc.
7
ConstantsConstants
Character and string constants
‘c’ , a single character in single quotes are stored as char.
Some special character are represented as two characters in single
quotes.
‘n’ = newline, ‘t’= tab, ‘’ = backlash, ‘”’ = double quotes.
Char constants also can be written in terms of their ASCII code.
‘060’ = ‘0’ (Decimal code is 48).
A sequence of characters enclosed in double quotes is called a string
constant or string literal. For example
“Charu”
“A”
“3/9”
“x = 5”
8
VariablesVariables
Naming a Variable
Must be a valid identifier.
Must not be a keyword
Names are case sensitive.
Variables are identified by only first 32 characters.
Library commonly uses names beginning with _.
Naming Styles: Uppercase style and Underscore style
lowerLimit lower_limit
incomeTax income_tax
9
DeclarationsDeclarations
Declaring a Variable
Each variable used must be declared.
A form of a declaration statement is
data-type var1, var2,…;
Declaration announces the data type of a variable and allocates
appropriate memory location. No initial value (like 0 for integers) should
be assumed.
It is possible to assign an initial value to a variable in the declaration
itself.
data-type var = expression;
Examples
int sum = 0;
char newLine = ‘n’;
float epsilon = 1.0e-6;
10
Global and Local VariablesGlobal and Local Variables
Global Variables
These variables are
declared outside all
functions.
Life time of a global
variable is the entire
execution period of the
program.
Can be accessed by any
function defined below the
declaration, in a file.
/* Compute Area and Perimeter of a
circle */
#include <stdio.h>
float pi = 3.14159; /* Global */
main() {
float rad; /* Local */
printf( “Enter the radius “ );
scanf(“%f” , &rad);
if ( rad > 0.0 ) {
float area = pi * rad * rad;
float peri = 2 * pi * rad;
printf( “Area = %fn” , area );
printf( “Peri = %fn” , peri );
}
else
printf( “Negative radiusn”);
printf( “Area = %fn” , area );
}
/* Compute Area and Perimeter of a
circle */
#include <stdio.h>
float pi = 3.14159; /* Global */
main() {
float rad; /* Local */
printf( “Enter the radius “ );
scanf(“%f” , &rad);
if ( rad > 0.0 ) {
float area = pi * rad * rad;
float peri = 2 * pi * rad;
printf( “Area = %fn” , area );
printf( “Peri = %fn” , peri );
}
else
printf( “Negative radiusn”);
printf( “Area = %fn” , area );
}
11
Global and Local VariablesGlobal and Local Variables
Local Variables
These variables are
declared inside some
functions.
Life time of a local
variable is the entire
execution period of the
function in which it is
defined.
Cannot be accessed by any
other function.
In general variables
declared inside a block
are accessible only in
that block.
/* Compute Area and Perimeter of a
circle */
#include <stdio.h>
float pi = 3.14159; /* Global */
main() {
float rad; /* Local */
printf( “Enter the radius “ );
scanf(“%f” , &rad);
if ( rad > 0.0 ) {
float area = pi * rad * rad;
float peri = 2 * pi * rad;
printf( “Area = %fn” , area );
printf( “Peri = %fn” , peri );
}
else
printf( “Negative radiusn”);
printf( “Area = %fn” , area );
}
/* Compute Area and Perimeter of a
circle */
#include <stdio.h>
float pi = 3.14159; /* Global */
main() {
float rad; /* Local */
printf( “Enter the radius “ );
scanf(“%f” , &rad);
if ( rad > 0.0 ) {
float area = pi * rad * rad;
float peri = 2 * pi * rad;
printf( “Area = %fn” , area );
printf( “Peri = %fn” , peri );
}
else
printf( “Negative radiusn”);
printf( “Area = %fn” , area );
}
12
OperatorsOperators
Arithmetic Operators
+, - , *, / and the modulus operator %.
+ and – have the same precedence and associate left to right.
3 – 5 + 7 = ( 3 – 5 ) + 7 ≠ 3 – ( 5 + 7 )
3 + 7 – 5 + 2 = ( ( 3 + 7 ) – 5 ) + 2
*, /, % have the same precedence and associate left to right.
The +, - group has lower precendence than the *, / % group.
3 – 5 * 7 / 8 + 6 / 2
3 – 35 / 8 + 6 / 2
3 – 4.375 + 6 / 2
3 – 4.375 + 3
-1.375 + 3
1.625
13
OperatorsOperators
Arithmetic Operators
% is a modulus operator. x % y results in the remainder when x is divided
by y and is zero when x is divisible by y.
Cannot be applied to float or double variables.
Example
if ( num % 2 == 0 )
printf(“%d is an even numbern”, num)’;
else
printf(“%d is an odd numbern”, num);
Lectures on Numerical Methods 14
Type ConversionsType Conversions
The operands of a binary operator must have a the same type and the
result is also of the same type.
Integer division:
c = (9 / 5)*(f - 32)
The operands of the division are both int and hence the result also would
be int. For correct results, one may write
c = (9.0 / 5.0)*(f - 32)
In case the two operands of a binary operator are different, but
compatible, then they are converted to the same type by the compiler.
The mechanism (set of rules) is called Automatic Type Casting.
c = (9.0 / 5)*(f - 32)
It is possible to force a conversion of an operand. This is called Explicit
Type casting.
c = ((float) 9 / 5)*(f - 32)
15
Automatic Type CastingAutomatic Type Casting
1. char and short operands are converted to int
2. Lower data types are converted to the higher data
types and result is of higher type.
3. The conversions between unsigned and signed types
may not yield intuitive results.
4. Example
float f; double d; long l;
int i; short s;
d + f f will be converted to double
i / s s will be converted to int
l / i i is converted to long; long result
Hierarchy
Double
float
long
Int
Short and
char
16
Explicit Type CastingExplicit Type Casting
The general form of a type casting operator is
(type-name) expression
It is generally a good practice to use explicit casts than to rely on
automatic type conversions.
Example
C = (float)9 / 5 * ( f – 32 )
float to int conversion causes truncation of fractional part
double to float conversion causes rounding of digits
long int to int causes dropping of the higher order bits.
17
Precedence and Order of evaluationPrecedence and Order of evaluation
Lectures on Numerical Methods 18
Precedence and Order of evaluationPrecedence and Order of evaluation
19
OperatorsOperators
Relational Operators
<, <=, > >=, ==, != are the relational operators. The expression
operand1 relational-operator operand2
takes a value of 1(int) if the relationship is true and 0(int) if relationship is
false.
Example
int a = 25, b = 30, c, d;
c = a < b;
d = a > b;
value of c will be 1 and that of d will be 0.
20
OperatorsOperators
Logical Operators
&&, || and ! are the three logical operators.
expr1 && expr2 has a value 1 if expr1 and expr2 both are nonzero.
expr1 || expr2 has a value 1 if expr1 and expr2 both are nonzero.
!expr1 has a value 1 if expr1 is zero else 0.
Example
if ( marks >= 40 && attendance >= 75 ) grade = ‘P’
If ( marks < 40 || attendance < 75 ) grade = ‘N’
21
OperatorsOperators
Assignment operators
The general form of an assignment operator is
v op= exp
Where v is a variable and op is a binary arithmetic operator. This
statement is equivalent to
v = v op (exp)
a = a + b can be written as a += b
a = a * b can be written as a *= b
a = a / b can be written as a /= b
a = a - b can be written as a -= b
22
OperatorsOperators
Increment and Decrement Operators
The operators ++ and –- are called increment and decrement operators.
a++ and ++a are equivalent to a += 1.
a-- and --a are equivalent to a -= 1.
++a op b is equivalent to a ++; a op b;
a++ op b is equivalent to a op b; a++;
Example
Let b = 10 then
(++b)+b+b = 33
b+(++b)+b = 33
b+b+(++b) = 31
b+b*(++b) = 132

More Related Content

What's hot

Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
Abed Bukhari
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 
Cbasic
CbasicCbasic
Introduction
IntroductionIntroduction
Introduction
Komal Pardeshi
 
What is c
What is cWhat is c
What is c
pacatarpit
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
Chitrank Dixit
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.Sivakumar
Sivakumar R D .
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
nmahi96
 
C language basics
C language basicsC language basics
C language basics
Milind Deshkar
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
CIMAP
 
Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
natarafonseca
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
KRUNAL RAVAL
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
nmahi96
 
Computer programming(CP)
Computer programming(CP)Computer programming(CP)
Computer programming(CP)
nmahi96
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
Chitrank Dixit
 

What's hot (20)

Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Cbasic
CbasicCbasic
Cbasic
 
Introduction
IntroductionIntroduction
Introduction
 
What is c
What is cWhat is c
What is c
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.Sivakumar
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
C language basics
C language basicsC language basics
C language basics
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
Computer programming(CP)
Computer programming(CP)Computer programming(CP)
Computer programming(CP)
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 

Viewers also liked

Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)
guest91cc85
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
Dattatray Gandhmal
 
Life at kssem
Life at kssemLife at kssem
Life at kssem
Dr. S.N. Sridhara
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
Dattatray Gandhmal
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
I/O Buffering
I/O BufferingI/O Buffering
I/O Buffering
Nadhrah Nini
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
Dattatray Gandhmal
 
Faculty development programme at kssem, bangalore
Faculty development programme at kssem, bangaloreFaculty development programme at kssem, bangalore
Faculty development programme at kssem, bangalore
Dr. S.N. Sridhara
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
Sami Said
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
Ashwini Sonawane
 

Viewers also liked (11)

Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Life at kssem
Life at kssemLife at kssem
Life at kssem
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
I/O Buffering
I/O BufferingI/O Buffering
I/O Buffering
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Faculty development programme at kssem, bangalore
Faculty development programme at kssem, bangaloreFaculty development programme at kssem, bangalore
Faculty development programme at kssem, bangalore
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 

Similar to Token and operators

Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
z9819898203
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
YashwanthMalviya
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
Python
PythonPython
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
KrishanPalSingh39
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ck
seidounsemel
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
MdMahediHasan54
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
DinobandhuThokdarCST
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptx
Akash Baruah
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
valarpink
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
c_tutorial_2.ppt
c_tutorial_2.pptc_tutorial_2.ppt
c_tutorial_2.ppt
gitesh_nagar
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
www.ixxo.io
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
2. operator
2. operator2. operator
2. operator
Shankar Gangaju
 

Similar to Token and operators (20)

Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Python
PythonPython
Python
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ck
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptx
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
c_tutorial_2.ppt
c_tutorial_2.pptc_tutorial_2.ppt
c_tutorial_2.ppt
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
2. operator
2. operator2. operator
2. operator
 

More from Samsil Arefin

Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocol
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
Samsil Arefin
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysis
Samsil Arefin
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)
Samsil Arefin
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
Samsil Arefin
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
Samsil Arefin
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
Samsil Arefin
 
Number theory
Number theoryNumber theory
Number theory
Samsil Arefin
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
Samsil Arefin
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
Samsil Arefin
 
Stack
StackStack
Sorting
SortingSorting
Sorting
Samsil Arefin
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuit
Samsil Arefin
 
Cyber security
Cyber securityCyber security
Cyber security
Samsil Arefin
 
C programming
C programmingC programming
C programming
Samsil Arefin
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin
 
Structure and union
Structure and unionStructure and union
Structure and union
Samsil Arefin
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
Samsil Arefin
 

More from Samsil Arefin (20)

Transmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocolTransmission Control Protocol and User Datagram protocol
Transmission Control Protocol and User Datagram protocol
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
 
Evolution Phylogenetic
Evolution PhylogeneticEvolution Phylogenetic
Evolution Phylogenetic
 
Ego net facebook data analysis
Ego net facebook data analysisEgo net facebook data analysis
Ego net facebook data analysis
 
Augmented Reality (AR)
Augmented Reality (AR)Augmented Reality (AR)
Augmented Reality (AR)
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
 
Number theory
Number theoryNumber theory
Number theory
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
Stack
StackStack
Stack
 
Sorting
SortingSorting
Sorting
 
Fundamentals of-electric-circuit
Fundamentals of-electric-circuitFundamentals of-electric-circuit
Fundamentals of-electric-circuit
 
Cyber security
Cyber securityCyber security
Cyber security
 
C programming
C programmingC programming
C programming
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
Structure and union
Structure and unionStructure and union
Structure and union
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 

Recently uploaded

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 

Recently uploaded (20)

New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 

Token and operators

  • 1. 1 Tokens in CTokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter. Underscore ( _ ) is treated as a letter. Identifiers are case sensitive. Identifiers are used to name variables, functions etc. Valid: Root, _getchar, __sin, x1, x2, x3, x_1, If Invalid: 324, short, price$, My Name Constants Constants like 13, ‘a’, 1.3e-5 etc.
  • 2. 2 Tokens in CTokens in C String Literals A sequence of characters enclosed in double quotes as “…”. For example “13” is a string literal and not number 13. ‘a’ and “a” are different. Operators Arithmetic operators like +, -, *, / ,% etc. Logical operators like ||, &&, ! etc. and so on. White Spaces Spaces, new lines, tabs, comments ( A sequence of characters enclosed in /* and */ ) etc. These are used to separate the adjacent identifiers, kewords and constants.
  • 3. 3 Basic Data TypesBasic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign bit is 0, the number is treated as positive. Bit pattern 01001011 = 75 (decimal). The largest positive number is 01111111 = 27 – 1 = 127. Negative numbers are stored as two’s complement or as one’s complement. -75 = 10110100 (one’s complement). -75 = 10110101 (two’s complement).
  • 4. 4 Basic Data TypesBasic Data Types Integral Types char Stored as 8 bits. Unsigned 0 to 255. Signed -128 to 127. short int Stored as 16 bits. Unsigned 0 to 65535. Signed -32768 to 32767. int Same as either short or long int. long int Stored as 32 bits. Unsigned 0 to 4294967295. Signed -2147483648 to 2147483647
  • 5. 5 Basic Data TypesBasic Data Types Floating Point Numbers Floating point numbers are rational numbers. Always signed numbers. float Approximate precision of 6 decimal digits . • Typically stored in 4 bytes with 24 bits of signed mantissa and 8 bits of signed exponent. double Approximate precision of 14 decimal digits. • Typically stored in 8 bytes with 56 bits of signed mantissa and 8 bits of signed exponent. One should check the file limits.h to what is implemented on a particular machine.
  • 6. 6 ConstantsConstants Numerical Constants Constants like 12, 253 are stored as int type. No decimal point. 12L or 12l are stored as long int. 12U or 12u are stored as unsigned int. 12UL or 12ul are stored as unsigned long int. Numbers with a decimal point (12.34) are stored as double. Numbers with exponent (12e-3 = 12 x 10-3 ) are stored as double. 12.34f or 1.234e1f are stored as float. These are not valid constants: 25,000 7.1e 4 $200 2.3e-3.4 etc.
  • 7. 7 ConstantsConstants Character and string constants ‘c’ , a single character in single quotes are stored as char. Some special character are represented as two characters in single quotes. ‘n’ = newline, ‘t’= tab, ‘’ = backlash, ‘”’ = double quotes. Char constants also can be written in terms of their ASCII code. ‘060’ = ‘0’ (Decimal code is 48). A sequence of characters enclosed in double quotes is called a string constant or string literal. For example “Charu” “A” “3/9” “x = 5”
  • 8. 8 VariablesVariables Naming a Variable Must be a valid identifier. Must not be a keyword Names are case sensitive. Variables are identified by only first 32 characters. Library commonly uses names beginning with _. Naming Styles: Uppercase style and Underscore style lowerLimit lower_limit incomeTax income_tax
  • 9. 9 DeclarationsDeclarations Declaring a Variable Each variable used must be declared. A form of a declaration statement is data-type var1, var2,…; Declaration announces the data type of a variable and allocates appropriate memory location. No initial value (like 0 for integers) should be assumed. It is possible to assign an initial value to a variable in the declaration itself. data-type var = expression; Examples int sum = 0; char newLine = ‘n’; float epsilon = 1.0e-6;
  • 10. 10 Global and Local VariablesGlobal and Local Variables Global Variables These variables are declared outside all functions. Life time of a global variable is the entire execution period of the program. Can be accessed by any function defined below the declaration, in a file. /* Compute Area and Perimeter of a circle */ #include <stdio.h> float pi = 3.14159; /* Global */ main() { float rad; /* Local */ printf( “Enter the radius “ ); scanf(“%f” , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %fn” , area ); printf( “Peri = %fn” , peri ); } else printf( “Negative radiusn”); printf( “Area = %fn” , area ); } /* Compute Area and Perimeter of a circle */ #include <stdio.h> float pi = 3.14159; /* Global */ main() { float rad; /* Local */ printf( “Enter the radius “ ); scanf(“%f” , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %fn” , area ); printf( “Peri = %fn” , peri ); } else printf( “Negative radiusn”); printf( “Area = %fn” , area ); }
  • 11. 11 Global and Local VariablesGlobal and Local Variables Local Variables These variables are declared inside some functions. Life time of a local variable is the entire execution period of the function in which it is defined. Cannot be accessed by any other function. In general variables declared inside a block are accessible only in that block. /* Compute Area and Perimeter of a circle */ #include <stdio.h> float pi = 3.14159; /* Global */ main() { float rad; /* Local */ printf( “Enter the radius “ ); scanf(“%f” , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %fn” , area ); printf( “Peri = %fn” , peri ); } else printf( “Negative radiusn”); printf( “Area = %fn” , area ); } /* Compute Area and Perimeter of a circle */ #include <stdio.h> float pi = 3.14159; /* Global */ main() { float rad; /* Local */ printf( “Enter the radius “ ); scanf(“%f” , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %fn” , area ); printf( “Peri = %fn” , peri ); } else printf( “Negative radiusn”); printf( “Area = %fn” , area ); }
  • 12. 12 OperatorsOperators Arithmetic Operators +, - , *, / and the modulus operator %. + and – have the same precedence and associate left to right. 3 – 5 + 7 = ( 3 – 5 ) + 7 ≠ 3 – ( 5 + 7 ) 3 + 7 – 5 + 2 = ( ( 3 + 7 ) – 5 ) + 2 *, /, % have the same precedence and associate left to right. The +, - group has lower precendence than the *, / % group. 3 – 5 * 7 / 8 + 6 / 2 3 – 35 / 8 + 6 / 2 3 – 4.375 + 6 / 2 3 – 4.375 + 3 -1.375 + 3 1.625
  • 13. 13 OperatorsOperators Arithmetic Operators % is a modulus operator. x % y results in the remainder when x is divided by y and is zero when x is divisible by y. Cannot be applied to float or double variables. Example if ( num % 2 == 0 ) printf(“%d is an even numbern”, num)’; else printf(“%d is an odd numbern”, num);
  • 14. Lectures on Numerical Methods 14 Type ConversionsType Conversions The operands of a binary operator must have a the same type and the result is also of the same type. Integer division: c = (9 / 5)*(f - 32) The operands of the division are both int and hence the result also would be int. For correct results, one may write c = (9.0 / 5.0)*(f - 32) In case the two operands of a binary operator are different, but compatible, then they are converted to the same type by the compiler. The mechanism (set of rules) is called Automatic Type Casting. c = (9.0 / 5)*(f - 32) It is possible to force a conversion of an operand. This is called Explicit Type casting. c = ((float) 9 / 5)*(f - 32)
  • 15. 15 Automatic Type CastingAutomatic Type Casting 1. char and short operands are converted to int 2. Lower data types are converted to the higher data types and result is of higher type. 3. The conversions between unsigned and signed types may not yield intuitive results. 4. Example float f; double d; long l; int i; short s; d + f f will be converted to double i / s s will be converted to int l / i i is converted to long; long result Hierarchy Double float long Int Short and char
  • 16. 16 Explicit Type CastingExplicit Type Casting The general form of a type casting operator is (type-name) expression It is generally a good practice to use explicit casts than to rely on automatic type conversions. Example C = (float)9 / 5 * ( f – 32 ) float to int conversion causes truncation of fractional part double to float conversion causes rounding of digits long int to int causes dropping of the higher order bits.
  • 17. 17 Precedence and Order of evaluationPrecedence and Order of evaluation
  • 18. Lectures on Numerical Methods 18 Precedence and Order of evaluationPrecedence and Order of evaluation
  • 19. 19 OperatorsOperators Relational Operators <, <=, > >=, ==, != are the relational operators. The expression operand1 relational-operator operand2 takes a value of 1(int) if the relationship is true and 0(int) if relationship is false. Example int a = 25, b = 30, c, d; c = a < b; d = a > b; value of c will be 1 and that of d will be 0.
  • 20. 20 OperatorsOperators Logical Operators &&, || and ! are the three logical operators. expr1 && expr2 has a value 1 if expr1 and expr2 both are nonzero. expr1 || expr2 has a value 1 if expr1 and expr2 both are nonzero. !expr1 has a value 1 if expr1 is zero else 0. Example if ( marks >= 40 && attendance >= 75 ) grade = ‘P’ If ( marks < 40 || attendance < 75 ) grade = ‘N’
  • 21. 21 OperatorsOperators Assignment operators The general form of an assignment operator is v op= exp Where v is a variable and op is a binary arithmetic operator. This statement is equivalent to v = v op (exp) a = a + b can be written as a += b a = a * b can be written as a *= b a = a / b can be written as a /= b a = a - b can be written as a -= b
  • 22. 22 OperatorsOperators Increment and Decrement Operators The operators ++ and –- are called increment and decrement operators. a++ and ++a are equivalent to a += 1. a-- and --a are equivalent to a -= 1. ++a op b is equivalent to a ++; a op b; a++ op b is equivalent to a op b; a++; Example Let b = 10 then (++b)+b+b = 33 b+(++b)+b = 33 b+b+(++b) = 31 b+b*(++b) = 132

Editor's Notes

  1. C is strongly typed. The variables and constants etc have a certain data types. All variables could have been double type, but then multiplying double numbers is very expensive. So the various data types have been provided for the reason of efficiency and ease of handling.
  2. C guarantees only following: Sizeof(short) &amp;lt;= sizeof(int) &amp;lt;= sizeof(long).