SlideShare a Scribd company logo
1 of 22
A Closer Look at Data
Types, Variables and Expressions
BY
MD.INAN MASHRUR.
DATA TYPES
DataTypes
IntegerTypes
CharacterTypes
FloatingTypes
Unsigned int
long int
char
long double
doublefloatShort int
Integer Types
• Values of an integer type are whole numbers.
• The int type is usually 32 bits, but may be 16 bits on older CPUs.
• Long integers may have more bits than ordinary integers; short integers may have fewer bits.
• The specifiers long and short, as well as signed and unsigned, can be combined with int to form
integer types.
• Only six combinations produce different types:
short int int long int
unsigned int unsigned short int unsigned long int
• The order of the specifiers doesn’t matter. Also, the word int can be dropped (long int can be
abbreviated to just long).
Signed & Unsigned Integer
• The integer types, in turn, are divided into two categories: signed and unsigned.
• The leftmost bit of a signed integer (known as the sign bit) is 0 if the number is
positive or zero, 1 if it’s negative.
• An integer with no sign bit (the leftmost bit is considered part of the number’s
magnitude) is said to be unsigned.
• By default, integer variables are signed in C—the leftmost bit is reserved for the sign.
• To tell the compiler that a variable has no sign bit, declare it to be unsigned.
• Unsigned numbers are primarily useful for systems programming and low-level,
machine-dependent applications.
Integer Types Defined By ANSI C
Standard
Type
Int
Unsigned int
Signed int
Short int
Unsigned short int
Signed short int
Long int
Signed long int
Unsigned long int
Long long int
Unsigned long long -
int
Typical Size in Bits
16 or 32
16 or 32
16 or 32
16
16
16
32
32
32
64
64
Minimal Range
-32,767 to 32,767
0 to 65,535
Same as int
Same as int
0 to 65,535
Same as short int
-2,147,483,647 to 2,147,483,647
Same as long int
0 to 4,294,967,295
-263 to 263 – 1
0 to 264 – 1
Floating Types
• C provides three floating types, corresponding to different floating-point
formats:
• float Single-precision floating-point
• double Double-precision floating-point
• long double Extended-precision floating-point
• float is suitable when the amount of precision isn’t critical.
• double provides enough precision for most programs.
• long double is rarely used.
• The C standard doesn’t state how much precision the float, double,
and long double types provide, since that depends on how numbers
are stored.
Floating Types Defined By ANSI C
Standard
Type
Float
Double
Long double
Typical size in Bits
32
64
80
Minimal Range
Six digits of precision
Ten digits of precision
Ten digits of precision
Character Types
• The only remaining basic type is char, the character type.
• Today’s most popular character set is ASCII (American
StandardCode for Information Interchange), a 7-bit code
capable of representing 128 characters.
• ASCII is often extended to a 256-character code known as
Latin-1 that provides the characters necessary forWestern
European and many African languages.
Operations on Characters
• When a character appears in a computation, C uses its
integer value.
• Consider the following examples, which assume the ASCII
character set:
char ch;
int i;
i = 'a'; /* i is now 97 */
ch = 65; /* ch is now 'A' */
ch = ch + 1; /* ch is now 'B' */
ch++; /* ch is now 'C' */
• Characters can be compared, just as numbers can.
• An if statement that converts a lower-case letter to upper case:
if (ch >= ‘a’ && ch <= 'z')
ch = ch - 'a' + 'A';
• Comparisons such as ch>=‘a’ are done using the integer values of
the characters involved.The fact that characters have the same
properties as numbers has advantages.
• For example, it is easy to write a for statement whose control variable
steps through all the upper-case letters:
for (ch = 'A'; ch <= 'Z'; ch++)…
Character Types Defined By ANSI C
Standard
Type
Char
Unsigned char
Signed char
Typical Size in Bits
8
8
8
Minimal Range
-127 to 127
0 to 255
-127 to 127
Format Specifiers for Different Data Types
DataType
Unsigned
Short
Int
Long int
Long long int
Float
Double
Long double
Char
Format Specifiers
%u
%h
%d
%ld
%lld
%f
%lf
%Lf
%c
Declaring Variables
Variables
Local Global
LocalVariables: Local variables will be declared inside a function . Different functions
can have variables with the same name as local variables are not known
outside their own function.
GlobalVariables: Global variables will be declared outside of all functions. It is known
by all functions.
A variables is a named memory location that can hold various values.
Example:
#include<stdio.h>
void f1(void);
int max; /*This is GlobalVariable*/
int main()
{ max = 10; f1(); return 0;}
void f1(void)
{ int i ; /*This is LocalVariable*/
for ( i=0; i<max; i++) printf(“%d”,i ) ; }
Constants
Constants refer to fixed values that may not be altered by the
program.
Integer type constant : Integer type constants are specified as
numbers without fractional component . Ex: int i = 10 ;
Floating type constant : Floating type constants are specified as
numbers with fractional component . Ex: int i= 10.07 ;
Character type constant : Character type constants are enclosed
between single quotes . Ex: char ch = ‘A’ ;
String type constant : A string is a set of characters enclosed by
double quotes. Ex: char ch = “Bangladesh” ;
INITIALIZE VARIABLES
A variable may be given an initial value when it is
declared.This is called variable initialization.
Examples:
1. int i = 10 ;
2. int I = 10 .07;
3. char ch = ‘A’ ;
4. char ch = “Bangladesh” ;
Type Conversations In
Expressions
• C allows the mixing of types within an expressions
because it has a strict set of conversion rules that dictate
how type differences are resolved.
Integral promotion : In C, whenever a char or short
int is used in an expression , its value
is automatically elevated to int
during the evaluation of that
expression .
Type Promotion : After automatic integral promotions have been applied,
the C compiler will convert all operands “up” to the type of the largest
operand. It is done on an operation-by-operation basis, as described
below:
if an operand is a long double
then the second is converted to long double
else if an operand is a double
then the second is converted to double
else if an operand is a float
then the second is converted to float
else if an operand is a unsigned long
then the second is converted to unsigned long
else if an operand is a long
then the second is converted to long
else if an operand is a unsigned
then the second is converted to unsigned
Type Conversations In
Assignments
In an assignment statement, in C, when the type of the left side is
larger than the type of the right side, the process cause no
problem. In opposite case, data loss may occur.
For Example :
Going from long long to long : 32 bits data will be lost
Going from long to int : 16 bits data will be lost
Going from int to char : 8 bits data will be lost
Going from double to int : fractional part will be lost
Going from long double to double : precision will be lost
Going from double to float : precision will be lost
Type Casting
Sometimes we need to transform the type of the variable
temporarily. Type cast causes a temporary type change.
General form of type cast:
(type) value
For example:
float f ;
f = 100.2 ;
printf(“%d”,(int) f ) ; /*print f as an integer*/
Here, the type cast causes the value of f (float) to be
converted to an integer
• Reference:
TeachYourself C by Herbert Schildt.
The End
THANKS FOR YOUR ATTENTION

More Related Content

What's hot

Data types in c language
Data types in c languageData types in c language
Data types in c languageHarihamShiwani
 
Data Types in C
Data Types in CData Types in C
Data Types in Cyarkhosh
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1patcha535
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++Abdul Hafeez
 
Data types in C language
Data types in C languageData types in C language
Data types in C languagekashyap399
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answerVasuki Ramasamy
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programmingRumman Ansari
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by FaixanٖFaiXy :)
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSaranyaK68
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2rohassanie
 
C programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesC programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesSourav Ganguly
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data TypesRushdi Shams
 

What's hot (20)

Data types in c language
Data types in c languageData types in c language
Data types in c language
 
Data Types in C
Data Types in CData Types in C
Data Types in C
 
Anti-Patterns
Anti-PatternsAnti-Patterns
Anti-Patterns
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
 
JAVA Literals
JAVA LiteralsJAVA Literals
JAVA Literals
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
2 1 data
2 1  data2 1  data
2 1 data
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C++ data types
C++ data typesC++ data types
C++ data types
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
C programming language character set keywords constants variables data types
C programming language character set keywords constants variables data typesC programming language character set keywords constants variables data types
C programming language character set keywords constants variables data types
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data Types
 

Similar to A Closer Look at Data Types, Variables and Expressions

Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)jahanullah
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_outputAnil Dutt
 
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 JyothiSowmyaJyothi3
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxjoachimbenedicttulau
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptpubgnewstate1620
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
CONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CCONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CSahithi Naraparaju
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variableseShikshak
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.pptFatimaZafar68
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
lecture 3 bca 1 year.pptx
lecture 3 bca 1 year.pptxlecture 3 bca 1 year.pptx
lecture 3 bca 1 year.pptxclassall
 
Lecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageLecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageSURAJ KUMAR
 

Similar to A Closer Look at Data Types, Variables and Expressions (20)

Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Ch7 Basic Types
Ch7 Basic TypesCh7 Basic Types
Ch7 Basic Types
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
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
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.ppt
 
Data Handling
Data HandlingData Handling
Data Handling
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
CONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CCONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN C
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
lecture 3 bca 1 year.pptx
lecture 3 bca 1 year.pptxlecture 3 bca 1 year.pptx
lecture 3 bca 1 year.pptx
 
Lecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageLecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming Language
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 

A Closer Look at Data Types, Variables and Expressions

  • 1. A Closer Look at Data Types, Variables and Expressions BY MD.INAN MASHRUR.
  • 3. Integer Types • Values of an integer type are whole numbers. • The int type is usually 32 bits, but may be 16 bits on older CPUs. • Long integers may have more bits than ordinary integers; short integers may have fewer bits. • The specifiers long and short, as well as signed and unsigned, can be combined with int to form integer types. • Only six combinations produce different types: short int int long int unsigned int unsigned short int unsigned long int • The order of the specifiers doesn’t matter. Also, the word int can be dropped (long int can be abbreviated to just long).
  • 4. Signed & Unsigned Integer • The integer types, in turn, are divided into two categories: signed and unsigned. • The leftmost bit of a signed integer (known as the sign bit) is 0 if the number is positive or zero, 1 if it’s negative. • An integer with no sign bit (the leftmost bit is considered part of the number’s magnitude) is said to be unsigned. • By default, integer variables are signed in C—the leftmost bit is reserved for the sign. • To tell the compiler that a variable has no sign bit, declare it to be unsigned. • Unsigned numbers are primarily useful for systems programming and low-level, machine-dependent applications.
  • 5. Integer Types Defined By ANSI C Standard Type Int Unsigned int Signed int Short int Unsigned short int Signed short int Long int Signed long int Unsigned long int Long long int Unsigned long long - int Typical Size in Bits 16 or 32 16 or 32 16 or 32 16 16 16 32 32 32 64 64 Minimal Range -32,767 to 32,767 0 to 65,535 Same as int Same as int 0 to 65,535 Same as short int -2,147,483,647 to 2,147,483,647 Same as long int 0 to 4,294,967,295 -263 to 263 – 1 0 to 264 – 1
  • 6. Floating Types • C provides three floating types, corresponding to different floating-point formats: • float Single-precision floating-point • double Double-precision floating-point • long double Extended-precision floating-point • float is suitable when the amount of precision isn’t critical. • double provides enough precision for most programs. • long double is rarely used. • The C standard doesn’t state how much precision the float, double, and long double types provide, since that depends on how numbers are stored.
  • 7. Floating Types Defined By ANSI C Standard Type Float Double Long double Typical size in Bits 32 64 80 Minimal Range Six digits of precision Ten digits of precision Ten digits of precision
  • 8. Character Types • The only remaining basic type is char, the character type. • Today’s most popular character set is ASCII (American StandardCode for Information Interchange), a 7-bit code capable of representing 128 characters. • ASCII is often extended to a 256-character code known as Latin-1 that provides the characters necessary forWestern European and many African languages.
  • 9. Operations on Characters • When a character appears in a computation, C uses its integer value. • Consider the following examples, which assume the ASCII character set: char ch; int i; i = 'a'; /* i is now 97 */ ch = 65; /* ch is now 'A' */ ch = ch + 1; /* ch is now 'B' */ ch++; /* ch is now 'C' */
  • 10. • Characters can be compared, just as numbers can. • An if statement that converts a lower-case letter to upper case: if (ch >= ‘a’ && ch <= 'z') ch = ch - 'a' + 'A'; • Comparisons such as ch>=‘a’ are done using the integer values of the characters involved.The fact that characters have the same properties as numbers has advantages. • For example, it is easy to write a for statement whose control variable steps through all the upper-case letters: for (ch = 'A'; ch <= 'Z'; ch++)…
  • 11. Character Types Defined By ANSI C Standard Type Char Unsigned char Signed char Typical Size in Bits 8 8 8 Minimal Range -127 to 127 0 to 255 -127 to 127
  • 12. Format Specifiers for Different Data Types DataType Unsigned Short Int Long int Long long int Float Double Long double Char Format Specifiers %u %h %d %ld %lld %f %lf %Lf %c
  • 13. Declaring Variables Variables Local Global LocalVariables: Local variables will be declared inside a function . Different functions can have variables with the same name as local variables are not known outside their own function. GlobalVariables: Global variables will be declared outside of all functions. It is known by all functions. A variables is a named memory location that can hold various values.
  • 14. Example: #include<stdio.h> void f1(void); int max; /*This is GlobalVariable*/ int main() { max = 10; f1(); return 0;} void f1(void) { int i ; /*This is LocalVariable*/ for ( i=0; i<max; i++) printf(“%d”,i ) ; }
  • 15. Constants Constants refer to fixed values that may not be altered by the program. Integer type constant : Integer type constants are specified as numbers without fractional component . Ex: int i = 10 ; Floating type constant : Floating type constants are specified as numbers with fractional component . Ex: int i= 10.07 ; Character type constant : Character type constants are enclosed between single quotes . Ex: char ch = ‘A’ ; String type constant : A string is a set of characters enclosed by double quotes. Ex: char ch = “Bangladesh” ;
  • 16. INITIALIZE VARIABLES A variable may be given an initial value when it is declared.This is called variable initialization. Examples: 1. int i = 10 ; 2. int I = 10 .07; 3. char ch = ‘A’ ; 4. char ch = “Bangladesh” ;
  • 17. Type Conversations In Expressions • C allows the mixing of types within an expressions because it has a strict set of conversion rules that dictate how type differences are resolved. Integral promotion : In C, whenever a char or short int is used in an expression , its value is automatically elevated to int during the evaluation of that expression .
  • 18. Type Promotion : After automatic integral promotions have been applied, the C compiler will convert all operands “up” to the type of the largest operand. It is done on an operation-by-operation basis, as described below: if an operand is a long double then the second is converted to long double else if an operand is a double then the second is converted to double else if an operand is a float then the second is converted to float else if an operand is a unsigned long then the second is converted to unsigned long else if an operand is a long then the second is converted to long else if an operand is a unsigned then the second is converted to unsigned
  • 19. Type Conversations In Assignments In an assignment statement, in C, when the type of the left side is larger than the type of the right side, the process cause no problem. In opposite case, data loss may occur. For Example : Going from long long to long : 32 bits data will be lost Going from long to int : 16 bits data will be lost Going from int to char : 8 bits data will be lost Going from double to int : fractional part will be lost Going from long double to double : precision will be lost Going from double to float : precision will be lost
  • 20. Type Casting Sometimes we need to transform the type of the variable temporarily. Type cast causes a temporary type change. General form of type cast: (type) value For example: float f ; f = 100.2 ; printf(“%d”,(int) f ) ; /*print f as an integer*/ Here, the type cast causes the value of f (float) to be converted to an integer
  • 21. • Reference: TeachYourself C by Herbert Schildt.
  • 22. The End THANKS FOR YOUR ATTENTION