SlideShare a Scribd company logo
1 of 18
Tokens, Expression
Evaluation & Type
Casting
Agenda
❏ Tokens
❏ Expression Evaluation
❏ Type Casting
Tokens
❏ A token is the smallest element of a program that is
meaningful to the compiler. Tokens can be classified
as follows:
❏ Keywords
❏ Identifiers
❏ Constants
❏ Strings
❏ Special Symbols
❏ Operators
#include<stdio.h>
int c, d;
int main()
{
int a, b;
return 0;
}
Keywords
Identifiers / Variables
❏ There are certain rules that should be followed while
naming c identifiers:
❏ They must begin with a letter or underscore(_).
❏ They must consist of only letters, digits, or
underscore. No other special character is allowed.
❏ It should not be a keyword.
❏ It must not contain whitespace.
❏ It should be up to 31 characters long as only first
31 characters are significant.
Constants
❏ Constants are also like normal variables. But, only
difference is, their values can not be modified by the
program once they are defined. Constants refer to
fixed values. They are also called as literals.
❏ Constants may belong to any of the data
type.Syntax: const data_type variable_name; (or) const
data_type *variable_name;
Example : #define pi = 3.1416
Strings
❏ Strings are nothing but an array of characters ended
with a null character (‘0’).This null character
indicates the end of the string. Strings are always
enclosed in double quotes. Whereas, a character is
enclosed in single quotes in C and C++.
Special Symbols
❏ Brackets[]
❏ Parentheses()
❏ Braces{}
❏ comma (, )
❏ semi colon (;)
❏ asterick (*)
❏ assignment operator(=)
❏ pre processor(#)
Operators
❏ Unary Operators (++, --)
❏ Binary Operators
❏ Arithmetic operators
❏ Relational Operators
❏ Logical Operators
❏ Assignment Operators
❏ Conditional Operators
❏ Bitwise Operators
❏ Ternary Operators (? :)
Bitwise Operators vs. Logical Operators
(*Class Discussion Slide with O4)
❏ Logical Operators
&& ||
A = 10 , B = 20
# A > 10 && B <= 20
= F && T
= F
= 0
❏ Bitwise Operators
& |
A = 15 , B = 15
# A & B
= 15
Expression Evaluation
Expression Evaluation Let, a = 5
Type Casting
Converting one data type into another is known as type casting or, type-conversion. For example, if you
want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. You can convert the
values from one type to another explicitly using the cast operator as follows −
(type_name) expression
Consider the following example where the cast operator causes the division of one integer variable by
another to be performed as a floating-point operation −
#include <stdio.h>
Int main() {
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %fn", mean );
return 0;
}
When the above code is compiled and executed, it produces the following result −
Value of mean : 3.400000
It should be noted here that the cast operator has precedence over division, so the value of sum is first
converted to type double and finally it gets divided by count yielding a double value.
Implicit Type Casting
When the type conversion is performed automatically by
the compiler without programmers intervention, such type
of conversion is known as implicit type conversion or type
promotion.
int x;
for(x=97; x<=122; x++) {
printf("%c", x); /*Implicit casting from int to char thanks to %c*/
}
Explicit Type Casting
The type conversion performed by the programmer by posing the data type of
the expression of specific type is known as explicit type conversion. The explicit
type conversion is also known as type casting.
Type casting in c is done in the following form:
(data_type)expression;
where, data_type is any valid c data type, and expression may be constant,
variable or expression.
For example,
int x;
for(x=97; x<=122; x++) {
printf("%c", (char)x); /*Explicit casting from int to char*/
}
Type Casting
❏ Implicit
❏ Example:
char val = ‘a’;
int num = val;
❏ Explicit
❏ Example:
char val = ‘a’;
int num =(int) val;
Example
Consider the following code:
If we want to get the exact value of 7/5 then we need explicit casting from int to float:
Thanks

More Related Content

Similar to L3_Tokens, Expression Evaluation.pptx

Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfMMRF2
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptxganeshkarthy
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants Hemantha Kulathilake
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 
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.pptxKrishanPalSingh39
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++K Durga Prasad
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing TutorialMahira Banu
 

Similar to L3_Tokens, Expression Evaluation.pptx (20)

Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
C
CC
C
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
Week 08 - Identifier.pdf
Week 08 - Identifier.pdfWeek 08 - Identifier.pdf
Week 08 - Identifier.pdf
 
C++ programming
C++ programmingC++ programming
C++ programming
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
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
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
CHAPTER 2
CHAPTER 2CHAPTER 2
CHAPTER 2
 

More from SarowarSuman

Relational Algebra (1).pptx
Relational Algebra (1).pptxRelational Algebra (1).pptx
Relational Algebra (1).pptxSarowarSuman
 
Software requirement & specification .pptx
Software requirement & specification .pptxSoftware requirement & specification .pptx
Software requirement & specification .pptxSarowarSuman
 
Projectile_Motion_ppt.ppt
Projectile_Motion_ppt.pptProjectile_Motion_ppt.ppt
Projectile_Motion_ppt.pptSarowarSuman
 
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...SarowarSuman
 
Software Testing (1).pptx
Software Testing (1).pptxSoftware Testing (1).pptx
Software Testing (1).pptxSarowarSuman
 

More from SarowarSuman (6)

Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
Relational Algebra (1).pptx
Relational Algebra (1).pptxRelational Algebra (1).pptx
Relational Algebra (1).pptx
 
Software requirement & specification .pptx
Software requirement & specification .pptxSoftware requirement & specification .pptx
Software requirement & specification .pptx
 
Projectile_Motion_ppt.ppt
Projectile_Motion_ppt.pptProjectile_Motion_ppt.ppt
Projectile_Motion_ppt.ppt
 
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...
Enhancing-Entrance-Security-at-Daffodil-International-University-through-Tech...
 
Software Testing (1).pptx
Software Testing (1).pptxSoftware Testing (1).pptx
Software Testing (1).pptx
 

Recently uploaded

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 

L3_Tokens, Expression Evaluation.pptx

  • 2. Agenda ❏ Tokens ❏ Expression Evaluation ❏ Type Casting
  • 3. Tokens ❏ A token is the smallest element of a program that is meaningful to the compiler. Tokens can be classified as follows: ❏ Keywords ❏ Identifiers ❏ Constants ❏ Strings ❏ Special Symbols ❏ Operators #include<stdio.h> int c, d; int main() { int a, b; return 0; }
  • 5. Identifiers / Variables ❏ There are certain rules that should be followed while naming c identifiers: ❏ They must begin with a letter or underscore(_). ❏ They must consist of only letters, digits, or underscore. No other special character is allowed. ❏ It should not be a keyword. ❏ It must not contain whitespace. ❏ It should be up to 31 characters long as only first 31 characters are significant.
  • 6. Constants ❏ Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined. Constants refer to fixed values. They are also called as literals. ❏ Constants may belong to any of the data type.Syntax: const data_type variable_name; (or) const data_type *variable_name; Example : #define pi = 3.1416
  • 7. Strings ❏ Strings are nothing but an array of characters ended with a null character (‘0’).This null character indicates the end of the string. Strings are always enclosed in double quotes. Whereas, a character is enclosed in single quotes in C and C++.
  • 8. Special Symbols ❏ Brackets[] ❏ Parentheses() ❏ Braces{} ❏ comma (, ) ❏ semi colon (;) ❏ asterick (*) ❏ assignment operator(=) ❏ pre processor(#)
  • 9. Operators ❏ Unary Operators (++, --) ❏ Binary Operators ❏ Arithmetic operators ❏ Relational Operators ❏ Logical Operators ❏ Assignment Operators ❏ Conditional Operators ❏ Bitwise Operators ❏ Ternary Operators (? :)
  • 10. Bitwise Operators vs. Logical Operators (*Class Discussion Slide with O4) ❏ Logical Operators && || A = 10 , B = 20 # A > 10 && B <= 20 = F && T = F = 0 ❏ Bitwise Operators & | A = 15 , B = 15 # A & B = 15
  • 13. Type Casting Converting one data type into another is known as type casting or, type-conversion. For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. You can convert the values from one type to another explicitly using the cast operator as follows − (type_name) expression Consider the following example where the cast operator causes the division of one integer variable by another to be performed as a floating-point operation − #include <stdio.h> Int main() { int sum = 17, count = 5; double mean; mean = (double) sum / count; printf("Value of mean : %fn", mean ); return 0; } When the above code is compiled and executed, it produces the following result − Value of mean : 3.400000 It should be noted here that the cast operator has precedence over division, so the value of sum is first converted to type double and finally it gets divided by count yielding a double value.
  • 14. Implicit Type Casting When the type conversion is performed automatically by the compiler without programmers intervention, such type of conversion is known as implicit type conversion or type promotion. int x; for(x=97; x<=122; x++) { printf("%c", x); /*Implicit casting from int to char thanks to %c*/ }
  • 15. Explicit Type Casting The type conversion performed by the programmer by posing the data type of the expression of specific type is known as explicit type conversion. The explicit type conversion is also known as type casting. Type casting in c is done in the following form: (data_type)expression; where, data_type is any valid c data type, and expression may be constant, variable or expression. For example, int x; for(x=97; x<=122; x++) { printf("%c", (char)x); /*Explicit casting from int to char*/ }
  • 16. Type Casting ❏ Implicit ❏ Example: char val = ‘a’; int num = val; ❏ Explicit ❏ Example: char val = ‘a’; int num =(int) val;
  • 17. Example Consider the following code: If we want to get the exact value of 7/5 then we need explicit casting from int to float: