SlideShare a Scribd company logo
VARIABLE & DATATYPE
Session 2
OBJECTIVES
‱ Discuss variables
‱Differentiate between variables and constants
‱List the different data types and make use of them
in C programs
‱ Discuss arithmetic operators
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
2
VARIABLE
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
3
VARIABLE EXAMPLE
‱ BEGIN
‱ DISPlAY ‘Enter 2 numbers’
‱ INPUT A, B
‱ C = A + B
‱ DISPLAY C
‱ END
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
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
4
CONSTANT
‱ A constant is a value whose worth never changes.
‱ Example:
‱ 5 numeric / integer constant
‱ 5.3 numeric / float constant
‱ ‘Black’ string constant
‱ ‘C’ Character constant
‱ Variable holds constant values
‱ Int a=5;
‱ Char a=‘C’
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
5
IDENTIFIERS
‱ 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
‱ Some In correct identifier names
‱ 1sttest
‱ oh!god
‱ start...end
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
6
IDENTIFIERS
‱ 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
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
7
KEYWORD
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
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
8
DATA TYPES
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
9
o data type or
simply type is a
classification of data which
tells
the compiler or interpreter
how the programmer
intends to use the data.
o A data type provides a set
of values from which
an expression (i.e. variable,
function...) may take its
values.
INT DATA TYPE
‱ Stores numeric data
‱ int num;
‱ Cannot then store any other type of data like “Alan” or “abc”
‱ 16 bits (2 bytes)
‱ Integers in the range -32768 to 32767
‱
‱ Examples:
‱ 12322,
‱ 0,
‱ -232
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
10
#include<stdio.h>
void main()
{
Int i=98;
Int j=-67;
}
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
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
11
#include<stdio.h>
void main()
{
Float var=
28.00006;
}
DOUBLE
‱ Stores values containing decimal places
‱ double num;
‱ Precision of upto 10 digits
‱ 64 bits (8 bytes) of memory
‱ Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
12
#include<stdio.h>
void main()
{
DOUBLE var=
’28%’;
}
CHAR
‱ Stores a single character of information
‱ char gender; gender='M';
‱ 8 bits (1 byte) of memory
‱ Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
13
#include<stdio.h>
void main()
{
Char var= ’X’;
}
VOID
‱ Stores nothing
‱ Indicates the compiler that there is nothing to expect
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
14
RANGE
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
15
DECLARING VARIABLE
main ()
{
char abc; /*abc of type character */
int xyz; /*xyz of type integer */
float length; /*length of type float */
double area; /*area of type double */
long liteyrs; /*liteyrs of type long int */
short arm; /*arm of type short integer*/ }
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
16
Presented by: Muhammad Ehtisham Siddiqui (BSCS)
17

More Related Content

PPTX
C programming Tutorial Session 3
PPTX
C programming Tutorial Session 4
PPTX
C programming Tutorial Session 1
PPT
Basic concept of c++
PPTX
PPT
Basic of c &c++
ODP
(2) cpp imperative programming
PPT
Basics of c++
C programming Tutorial Session 3
C programming Tutorial Session 4
C programming Tutorial Session 1
Basic concept of c++
Basic of c &c++
(2) cpp imperative programming
Basics of c++

What's hot (20)

PDF
C++ Tokens
PDF
Assignment
PPT
C++ programming program design including data structures
PPTX
45 Days C++ Programming Language Training in Ambala
PPTX
Programming in c
PDF
Keywords, identifiers ,datatypes in C++
PPTX
Data Type in C Programming
PPTX
C++ AND CATEGORIES OF SOFTWARE
PPTX
C++ PROGRAMMING BASICS
PPT
Data type
PPTX
Learn C LANGUAGE at ASIT
 
PPTX
Variables and data types in C++
PPTX
Constant and variacles in c
PDF
Vhdl introduction
PPS
C language
PPT
constants, variables and datatypes in C
PPTX
C++ Programming Language Training in Ambala ! Batra Computer Centre
PPTX
Variables in C and C++ Language
PPTX
C Programming Introduction
PPT
02a fundamental c++ types, arithmetic
C++ Tokens
Assignment
C++ programming program design including data structures
45 Days C++ Programming Language Training in Ambala
Programming in c
Keywords, identifiers ,datatypes in C++
Data Type in C Programming
C++ AND CATEGORIES OF SOFTWARE
C++ PROGRAMMING BASICS
Data type
Learn C LANGUAGE at ASIT
 
Variables and data types in C++
Constant and variacles in c
Vhdl introduction
C language
constants, variables and datatypes in C
C++ Programming Language Training in Ambala ! Batra Computer Centre
Variables in C and C++ Language
C Programming Introduction
02a fundamental c++ types, arithmetic
Ad

Similar to C programming Tutorial Session 2 (20)

PPTX
COM1407: Variables and Data Types
PPT
work.ppt it describes about programming fundamentals
PPTX
Lecture 2
DOCX
PPTX
2. Variables and Data Types in C++ proramming.pptx
PPTX
Datatype and Operators used in C Programming
PPT
Data Handling
PPTX
Basic of Structered Programming in C psd
PDF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PPTX
Lecture 02 Programming C for Beginners 001
PPTX
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
PPTX
datatypes and variables in c language
PPTX
structured Programming Unit-2-Basic-Elements-of-C.pptx
PDF
POLITEKNIK MALAYSIA
PPTX
Constants, Variables, and Data Types
PPTX
Btech i pic u-2 datatypes and variables in c language
PPTX
data types in C programming
PDF
cassignmentii-170424105623.pdf
 
PPTX
dinoC_ppt.pptx
COM1407: Variables and Data Types
work.ppt it describes about programming fundamentals
Lecture 2
2. Variables and Data Types in C++ proramming.pptx
Datatype and Operators used in C Programming
Data Handling
Basic of Structered Programming in C psd
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Lecture 02 Programming C for Beginners 001
Bsc cs i pic u-2 datatypes and variables in c language
datatypes and variables in c language
structured Programming Unit-2-Basic-Elements-of-C.pptx
POLITEKNIK MALAYSIA
Constants, Variables, and Data Types
Btech i pic u-2 datatypes and variables in c language
data types in C programming
cassignmentii-170424105623.pdf
 
dinoC_ppt.pptx
Ad

More from Muhammad Ehtisham Siddiqui (20)

PPTX
C programming Tutorial Session 4
PPTX
HTML5 Web storage
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
PPTX
JavaScript Session 2
PPTX
JavaScript Session 3
PPTX
Javascript session 1
PPTX
Html audio video
PPTX
Html 5 geolocation api
PPTX
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session6
PPTX
Building Next Generation Websites Session5
PPTX
Building Next Generation Websites Session4
PPTX
Office session14
PPTX
Office session13
PPTX
Office session12
PPTX
Office session11
C programming Tutorial Session 4
HTML5 Web storage
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
JavaScript Session 2
JavaScript Session 3
Javascript session 1
Html audio video
Html 5 geolocation api
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session6
Building Next Generation Websites Session5
Building Next Generation Websites Session4
Office session14
Office session13
Office session12
Office session11

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administration Chapter 2
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Transform Your Business with a Software ERP System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
AI in Product Development-omnex systems
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
ai tools demonstartion for schools and inter college
Wondershare Filmora 15 Crack With Activation Key [2025
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administration Chapter 2
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Transform Your Business with a Software ERP System
Navsoft: AI-Powered Business Solutions & Custom Software Development
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
VVF-Customer-Presentation2025-Ver1.9.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 2 - PM Management and IT Context
AI in Product Development-omnex systems
wealthsignaloriginal-com-DS-text-... (1).pdf
Digital Strategies for Manufacturing Companies
ai tools demonstartion for schools and inter college

C programming Tutorial Session 2

  • 2. OBJECTIVES ‱ Discuss variables ‱Differentiate between variables and constants ‱List the different data types and make use of them in C programs ‱ Discuss arithmetic operators Presented by: Muhammad Ehtisham Siddiqui (BSCS) 2
  • 3. VARIABLE Presented by: Muhammad Ehtisham Siddiqui (BSCS) 3
  • 4. VARIABLE EXAMPLE ‱ BEGIN ‱ DISPlAY ‘Enter 2 numbers’ ‱ INPUT A, B ‱ C = A + B ‱ DISPLAY C ‱ END 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 Presented by: Muhammad Ehtisham Siddiqui (BSCS) 4
  • 5. CONSTANT ‱ A constant is a value whose worth never changes. ‱ Example: ‱ 5 numeric / integer constant ‱ 5.3 numeric / float constant ‱ ‘Black’ string constant ‱ ‘C’ Character constant ‱ Variable holds constant values ‱ Int a=5; ‱ Char a=‘C’ Presented by: Muhammad Ehtisham Siddiqui (BSCS) 5
  • 6. IDENTIFIERS ‱ 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 ‱ Some In correct identifier names ‱ 1sttest ‱ oh!god ‱ start...end Presented by: Muhammad Ehtisham Siddiqui (BSCS) 6
  • 7. IDENTIFIERS ‱ 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 Presented by: Muhammad Ehtisham Siddiqui (BSCS) 7
  • 8. KEYWORD 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 Presented by: Muhammad Ehtisham Siddiqui (BSCS) 8
  • 9. DATA TYPES Presented by: Muhammad Ehtisham Siddiqui (BSCS) 9 o data type or simply type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. o A data type provides a set of values from which an expression (i.e. variable, function...) may take its values.
  • 10. INT DATA TYPE ‱ Stores numeric data ‱ int num; ‱ Cannot then store any other type of data like “Alan” or “abc” ‱ 16 bits (2 bytes) ‱ Integers in the range -32768 to 32767 ‱ ‱ Examples: ‱ 12322, ‱ 0, ‱ -232 Presented by: Muhammad Ehtisham Siddiqui (BSCS) 10 #include<stdio.h> void main() { Int i=98; Int j=-67; }
  • 11. 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 Presented by: Muhammad Ehtisham Siddiqui (BSCS) 11 #include<stdio.h> void main() { Float var= 28.00006; }
  • 12. DOUBLE ‱ Stores values containing decimal places ‱ double num; ‱ Precision of upto 10 digits ‱ 64 bits (8 bytes) of memory ‱ Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’ Presented by: Muhammad Ehtisham Siddiqui (BSCS) 12 #include<stdio.h> void main() { DOUBLE var= ’28%’; }
  • 13. CHAR ‱ Stores a single character of information ‱ char gender; gender='M'; ‱ 8 bits (1 byte) of memory ‱ Examples: ‘a’, ‘m’, ‘$’ ‘%’ , ‘1’, ’5’ Presented by: Muhammad Ehtisham Siddiqui (BSCS) 13 #include<stdio.h> void main() { Char var= ’X’; }
  • 14. VOID ‱ Stores nothing ‱ Indicates the compiler that there is nothing to expect Presented by: Muhammad Ehtisham Siddiqui (BSCS) 14
  • 15. RANGE Presented by: Muhammad Ehtisham Siddiqui (BSCS) 15
  • 16. DECLARING VARIABLE main () { char abc; /*abc of type character */ int xyz; /*xyz of type integer */ float length; /*length of type float */ double area; /*area of type double */ long liteyrs; /*liteyrs of type long int */ short arm; /*arm of type short integer*/ } Presented by: Muhammad Ehtisham Siddiqui (BSCS) 16
  • 17. Presented by: Muhammad Ehtisham Siddiqui (BSCS) 17