SlideShare a Scribd company logo
1 of 15
Variables and Data Types
Session 2
Presented by: Sanjiv Kumar Sharma
Elementary Programming with C/Session 2/ 2 of 22
Objectives
 Discuss variables
 Differentiate between variables and constants
 List the different data types and make use of
them in C programs
 Discuss arithmetic operators
Elementary Programming with C/Session 2/ 3 of 22
Variables
Data
Memory
Each location in the memory is unique
Variables allow to provide a meaningful name for the location in memory
15
Data in memory
15
Elementary Programming with C/Session 2/ 4 of 22
Example
A, B and C are variables in the pseudocode
BEGIN
DISPlAY ‘Enter 2 numbers’
INPUT A, B
C = A + B
DISPLAY C
END
Variable names takes away the need for a programmer to access memory locations
using their address
The operating system takes care of allocating space for the variables
To refer to the value in the memory space, we need to only use the variable name
Elementary Programming with C/Session 2/ 5 of 22
 The names of variables, functions, labels, and various other user
defined objects are called identifiers
 Some correct identifier names
 arena
 s_count
 marks40
 class_one
 Examples of erroneous identifiers
 1sttest
 oh!god
 start... end
 Identifiers can be of any convenient length, but the number of
characters in a variable that are recognized by a compiler varies from
compiler to compiler
 Identifiers in C are case sensitive
Identifier Names
! is invalid
Elementary Programming with C/Session 2/ 6 of 22
Keywords
 Keywords : All languages reserve certain
words for their internal use
 Keywords hold a special meaning within the
context of the particular language
 No problem of conflict as long as the keyword
and the variable name can be distinguished.
For example, having integer as a variable
name is perfectly valid even though it
contains the keyword int
Elementary Programming with C/Session 2/ 7 of 22
Elementary Programming with C/Session 2/ 8 of 22
void
char
double
Basic Data Types
The basic data types are
float
int
Elementary Programming with C/Session 2/ 9 of 22
Type float
 Stores values containing decimal places
float num;
 Precision of upto 6 digits
 32 bits (4 bytes) of memory
 Examples: 23.05, 56.5, 32
Elementary Programming with C/Session 2/ 10 of 22
Type char
 Stores a single character of information
char gender;
gender='M';
 8 bits (1 byte) of memory
 Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
Elementary Programming with C/Session 2/ 11 of 22
Type void
 Stores nothing
 Indicates the compiler that there is nothing to
expect
Elementary Programming with C/Session 2/ 12 of 22
Derived Data Types
int
short short int
(Occupies less
memory
space than int)
Derived data type
Basic Data
types
Data type
Modifiers
int
unsigned int
(Permits only
positive numbers)
unsigned
int/double
Long int /longdouble
(Occupies more
space than
int/double)
long
Elementary Programming with C/Session 2/ 13 of 22
long and short Types
 short int occupies 8 bits (1 byte)
 allows numbers in the range -128 to 127
 long int occupies 32 bits (4 bytes)
 2,147,483,647 and 2,147,483,647
 long double occupies 128 bits (16 bytes)
Elementary Programming with C/Session 2/ 14 of 22
Data Types and their
range-2
Type Approximate
Size in Bits
Minimal Range
signed short int 8 Same as short int
signed short int 8 Same as short int
long int 32 -2,147,483,647 to 2,147,483,647
signed long int 32 0 to 4,294,967,295
unsigned long int 32 0 to 4,294,967,295
float 32 Six digits of precision
double 64 Ten digits of precision
long double 128 Ten digits of precision
Thank You
Elementary Programming with C/Session 2/ 15 of 22

More Related Content

Similar to work.ppt it describes about programming fundamentals

CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
BalamuruganV28
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 

Similar to work.ppt it describes about programming fundamentals (20)

Introduction To C
Introduction To CIntroduction To C
Introduction To C
 
Programming C Part 01
Programming C Part 01 Programming C Part 01
Programming C Part 01
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Intro
IntroIntro
Intro
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Theory1&2
Theory1&2Theory1&2
Theory1&2
 
Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
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
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 

work.ppt it describes about programming fundamentals

  • 1. Variables and Data Types Session 2 Presented by: Sanjiv Kumar Sharma
  • 2. Elementary Programming with C/Session 2/ 2 of 22 Objectives  Discuss variables  Differentiate between variables and constants  List the different data types and make use of them in C programs  Discuss arithmetic operators
  • 3. Elementary Programming with C/Session 2/ 3 of 22 Variables Data Memory Each location in the memory is unique Variables allow to provide a meaningful name for the location in memory 15 Data in memory 15
  • 4. Elementary Programming with C/Session 2/ 4 of 22 Example A, B and C are variables in the pseudocode BEGIN DISPlAY ‘Enter 2 numbers’ INPUT A, B C = A + B DISPLAY C END Variable names takes away the need for a programmer to access memory locations using their address The operating system takes care of allocating space for the variables To refer to the value in the memory space, we need to only use the variable name
  • 5. Elementary Programming with C/Session 2/ 5 of 22  The names of variables, functions, labels, and various other user defined objects are called identifiers  Some correct identifier names  arena  s_count  marks40  class_one  Examples of erroneous identifiers  1sttest  oh!god  start... end  Identifiers can be of any convenient length, but the number of characters in a variable that are recognized by a compiler varies from compiler to compiler  Identifiers in C are case sensitive Identifier Names ! is invalid
  • 6. Elementary Programming with C/Session 2/ 6 of 22 Keywords  Keywords : All languages reserve certain words for their internal use  Keywords hold a special meaning within the context of the particular language  No problem of conflict as long as the keyword and the variable name can be distinguished. For example, having integer as a variable name is perfectly valid even though it contains the keyword int
  • 7. Elementary Programming with C/Session 2/ 7 of 22
  • 8. Elementary Programming with C/Session 2/ 8 of 22 void char double Basic Data Types The basic data types are float int
  • 9. Elementary Programming with C/Session 2/ 9 of 22 Type float  Stores values containing decimal places float num;  Precision of upto 6 digits  32 bits (4 bytes) of memory  Examples: 23.05, 56.5, 32
  • 10. Elementary Programming with C/Session 2/ 10 of 22 Type char  Stores a single character of information char gender; gender='M';  8 bits (1 byte) of memory  Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
  • 11. Elementary Programming with C/Session 2/ 11 of 22 Type void  Stores nothing  Indicates the compiler that there is nothing to expect
  • 12. Elementary Programming with C/Session 2/ 12 of 22 Derived Data Types int short short int (Occupies less memory space than int) Derived data type Basic Data types Data type Modifiers int unsigned int (Permits only positive numbers) unsigned int/double Long int /longdouble (Occupies more space than int/double) long
  • 13. Elementary Programming with C/Session 2/ 13 of 22 long and short Types  short int occupies 8 bits (1 byte)  allows numbers in the range -128 to 127  long int occupies 32 bits (4 bytes)  2,147,483,647 and 2,147,483,647  long double occupies 128 bits (16 bytes)
  • 14. Elementary Programming with C/Session 2/ 14 of 22 Data Types and their range-2 Type Approximate Size in Bits Minimal Range signed short int 8 Same as short int signed short int 8 Same as short int long int 32 -2,147,483,647 to 2,147,483,647 signed long int 32 0 to 4,294,967,295 unsigned long int 32 0 to 4,294,967,295 float 32 Six digits of precision double 64 Ten digits of precision long double 128 Ten digits of precision
  • 15. Thank You Elementary Programming with C/Session 2/ 15 of 22