SlideShare a Scribd company logo
1 of 9
Lectures on Numerical Methods 1
Tokens in C
Tokens in C language are the smallest
elements or the building blocks used
to construct a C program. C Tokens are
of 6 types, and they are classified as:
Identifiers, Keywords, Constants,
Operators, Special Characters and Strings.
2
Tokens 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.
Lectures on Numerical Methods 3
Tokens 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, keywords and constants.
Lectures on Numerical Methods 4
Operators
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
Lectures on Numerical Methods 5
Operators
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 6
Operators
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.
Lectures on Numerical Methods 7
Operators
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’
Lectures on Numerical Methods 8
Operators
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
Lectures on Numerical Methods 9
Operators
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

Similar to lecture1.ppt

component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
Andrew Raj
 

Similar to lecture1.ppt (20)

Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Verilog operators.pptx
Verilog  operators.pptxVerilog  operators.pptx
Verilog operators.pptx
 
Introduction to Python Values, Variables Data Types Chapter 2
Introduction to Python  Values, Variables Data Types Chapter 2Introduction to Python  Values, Variables Data Types Chapter 2
Introduction to Python Values, Variables Data Types Chapter 2
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ck
 
comp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semanticscomp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semantics
 
Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming Language
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
2. operator
2. operator2. operator
2. operator
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
C language basics
C language basicsC language basics
C language basics
 
C language operator
C language operatorC language operator
C language operator
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
java_lect_03-2.ppt
java_lect_03-2.pptjava_lect_03-2.ppt
java_lect_03-2.ppt
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 

Recently uploaded

CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 

Recently uploaded (20)

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 

lecture1.ppt

  • 1. Lectures on Numerical Methods 1 Tokens in C Tokens in C language are the smallest elements or the building blocks used to construct a C program. C Tokens are of 6 types, and they are classified as: Identifiers, Keywords, Constants, Operators, Special Characters and Strings.
  • 2. 2 Tokens 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.
  • 3. Lectures on Numerical Methods 3 Tokens 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, keywords and constants.
  • 4. Lectures on Numerical Methods 4 Operators 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
  • 5. Lectures on Numerical Methods 5 Operators 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);
  • 6. Lectures on Numerical Methods 6 Operators 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.
  • 7. Lectures on Numerical Methods 7 Operators 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’
  • 8. Lectures on Numerical Methods 8 Operators 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
  • 9. Lectures on Numerical Methods 9 Operators 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