SlideShare a Scribd company logo
Concept
Of
Data Types
Lecture-06
REHAN IJAZ
By
ProgrammingFundamentals
 A Data Type is a Type of Data.
 Data types are the keywords, which are used for assigning a type to a
variable.
 Data Type is a Data Storage Format that can contain a Specific Type or
Range of Values.
 When computer programs store data in variables, each variable must be
assigned a specific data type.
 In C, variable(data) should be declared before it can be used in program.
 Whenever we declare variable in Computer’s memory, Computer must
know the type of the data to be stored inside the memory.
 When the compiler encounters a declaration for a variable, it sets up a
memory location for it
 If we need to store the single character then the size of memory occupied
will be different than storing the single integer number.
 The memory in our computers is organized in bytes.
 A byte is the minimum amount of memory that we can manage in C.
Syntax for declaration of a variable
data_type variable_name;
int var1;
int std_reg_no;
char std_gender;
• Built-in data types
– Fundamental data types (int, char, double, float, void, pointer)
– Derived data types (array, string, structure)
• Programmer-defined data types
– Structure
– Union
– Enumeration
Data Type keyword Description
Integer Data Type int Stores the Integer Value
Float Data Type float Stores the Floating Point Value
Character Data Type char Stores the Single Character Value
Long Data Type long Stores the Long range Integer Value
Double Data Type double Stores the long range Floating Value
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
−
To
int - data type
int is used to define integer numbers.
float - data type
float is used to define floating point numbers.
char - data type
char defines characters.
int rollno;
rollno = 5;
float kilometre;
kilometre = 5.6;
char section;
section = ‘D';
double - data type
double is used to define BIG floating point numbers. It
reserves twice the storage for the number. On PCs this is
likely to be 8 bytes.
double Atoms;
Atoms = 2500000;
pointer-data type
A pointer is a special kind of variable designed for storing memory address i.e. the
address of another variable.
Declaring a pointer is the same as declaring a normal variable except you stick an
asterisk '*' in front of the variables identifier.
There are two new operators you will need to know to work with pointers.
The "address of" operator '&' and the "dereferencing" operator '*'.
 When you place '&' in front of a variable you will get it's address, this can
be stored in a pointer vairable.
 When you place an '*' in front of a pointer you will get the value at the
memory address pointed to.
{
int *ptr, q;
/* address of q is assigned to ptr */
ptr = &q;
/* display q’s value using ptr variable */
printf(“%d”, *ptr);
Output:
A0250
Example of pointer
 An array is a collection of values, all of the same type, stored contiguously
in memory.
 An array of size N is indexed by integers from 0 up to and including N-1.
 There are also "arrays of unspecified size" where the number of elements
is not known by the compiler. Here is a brief
 1.One dimensional array
 2. Two dimensional array
array
Array (one dimensional)
#include<stdio.h>
int main()
{
int arr[5] = {10,20,30,40,50};
printf(“value of arr[0] is %d n”, arr[0]);
}
Output : 10
Syntax : data-type arr_name[array_size];
//or
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
0 1 2 3 4
4 5 3 1 9
Array (two dimensional)
int arr[2][2] = {10,20,30,40};
printf(“value of arr[%d] [%d] : n”,arr[1][0]);
Output : 30
syntax : data_type array_name[num_of_rows][num_of_column]
// or
arr[0][0] = 10;
arr[0][1] = 20;
arr[1][0] = 30;
arr[1][1] = 40;
0 1
0 10 20
1 30 40
To get the exact size of a type or a variable on a particular platform, you can use
the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in
bytes. Given below is an example to get the size of int type on any machine
#include<stdio.h>
#include<limits.h>
int main()
{
printf("Storage size for int : %d n", sizeof(int));
return 0;
}
sizeof(type)
Typecasting concept in C language is used to modify a variable from one date
type to another data type. New data type should be mentioned before the
variable name or value in brackets which to be typecast.
#include <stdio.h>
int main ()
{
float x;
x = (float) 7/5;
printf("%f",x);
}
Output: 1.400000
S.no Typecast function Description
1 atof() Converts string to float
2 atoi() Converts string to int
3 atol() Converts string to long
4 itoa() Converts int to string
5 ltoa() Converts long to string
Programming Fundamentals lecture 6

More Related Content

PPTX
Concept Of C++ Data Types
 
PPTX
data types in C programming
PPTX
Data types in C language
PPTX
C data types, arrays and structs
PPT
cs8251 unit 1 ppt
PPT
User defined data type
PPTX
PPTX
Data Types | CS8251- Programming in c | Learn Hub
Concept Of C++ Data Types
 
data types in C programming
Data types in C language
C data types, arrays and structs
cs8251 unit 1 ppt
User defined data type
Data Types | CS8251- Programming in c | Learn Hub

What's hot (20)

PPT
C++ data types
PPT
3 data-types-in-c
PPTX
Basic Data Types in C++
PPTX
Structures in c language
PPTX
Data types
PPTX
Data types in C
PPTX
Data types in C
PPT
Enumerated data types in C
PPTX
Data Types - Premetive and Non Premetive
PPTX
Variables in C++, data types in c++
PPT
Lect 9(pointers) Zaheer Abbas
PPTX
Concept of c data types
PPTX
Lecture 3.mte 407
PDF
Arraysincv109102017 180831194256
PPTX
Datatype in c++ unit 3 -topic 2
PDF
Buffersdirectx
PPTX
Numeric Data Types & Strings
PPT
Primitive data types
PPTX
Data types
C++ data types
3 data-types-in-c
Basic Data Types in C++
Structures in c language
Data types
Data types in C
Data types in C
Enumerated data types in C
Data Types - Premetive and Non Premetive
Variables in C++, data types in c++
Lect 9(pointers) Zaheer Abbas
Concept of c data types
Lecture 3.mte 407
Arraysincv109102017 180831194256
Datatype in c++ unit 3 -topic 2
Buffersdirectx
Numeric Data Types & Strings
Primitive data types
Data types
Ad

Similar to Programming Fundamentals lecture 6 (20)

PDF
cassignmentii-170424105623.pdf
DOCX
PPTX
C PROGRAMMING LANGUAGE
PPTX
Datatypes
PPSX
Data type
PPTX
Data types
PPT
Unit 1 Built in Data types in C language.ppt
PPTX
data types in c programming language in detail
PPTX
C language
PPTX
Basic C programming Language - Unit 1.pptx
PPT
Structured Programming with C - Data Types.ppt
PPTX
Data-Types-in-C-Programming.Programming.pptxProgramming.pptxpptx
PPT
C language Unit 2 Slides, UPTU C language
PPTX
Data types in C
PPTX
DATA TYPES IN C Language.pptx
PPTX
COM1407: Variables and Data Types
PPTX
TAPASH kumar das its my college pptasjhk
PDF
introduction to programming using ANSI C
PPTX
Data Types in C language
cassignmentii-170424105623.pdf
C PROGRAMMING LANGUAGE
Datatypes
Data type
Data types
Unit 1 Built in Data types in C language.ppt
data types in c programming language in detail
C language
Basic C programming Language - Unit 1.pptx
Structured Programming with C - Data Types.ppt
Data-Types-in-C-Programming.Programming.pptxProgramming.pptxpptx
C language Unit 2 Slides, UPTU C language
Data types in C
DATA TYPES IN C Language.pptx
COM1407: Variables and Data Types
TAPASH kumar das its my college pptasjhk
introduction to programming using ANSI C
Data Types in C language
Ad

More from REHAN IJAZ (14)

DOCX
How to make presentation effective assignment
DOCX
Project code for Project on Student information management system
DOCX
Programming Fundamentals lecture 8
PPTX
Introduction to artificial intelligence lecture 1
DOCX
Programming Fundamentals lecture 7
PPTX
Programming Fundamentals lecture 5
DOCX
Programming Fundamentals lecture 4
PPTX
Programming Fundamentals lecture 3
PPTX
Programming Fundamentals lecture 2
PPTX
Programming Fundamentals lecture 1
PDF
Career development interviews
DOC
importance of Communication in business
DOCX
Porposal on Student information management system
PPTX
Project on Student information management system
How to make presentation effective assignment
Project code for Project on Student information management system
Programming Fundamentals lecture 8
Introduction to artificial intelligence lecture 1
Programming Fundamentals lecture 7
Programming Fundamentals lecture 5
Programming Fundamentals lecture 4
Programming Fundamentals lecture 3
Programming Fundamentals lecture 2
Programming Fundamentals lecture 1
Career development interviews
importance of Communication in business
Porposal on Student information management system
Project on Student information management system

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Construction Project Organization Group 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
additive manufacturing of ss316l using mig welding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
composite construction of structures.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Internet of Things (IOT) - A guide to understanding
Construction Project Organization Group 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CH1 Production IntroductoryConcepts.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
UNIT 4 Total Quality Management .pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Foundation to blockchain - A guide to Blockchain Tech
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
additive manufacturing of ss316l using mig welding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
bas. eng. economics group 4 presentation 1.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
composite construction of structures.pdf

Programming Fundamentals lecture 6

  • 2.  A Data Type is a Type of Data.  Data types are the keywords, which are used for assigning a type to a variable.  Data Type is a Data Storage Format that can contain a Specific Type or Range of Values.  When computer programs store data in variables, each variable must be assigned a specific data type.  In C, variable(data) should be declared before it can be used in program.
  • 3.  Whenever we declare variable in Computer’s memory, Computer must know the type of the data to be stored inside the memory.  When the compiler encounters a declaration for a variable, it sets up a memory location for it  If we need to store the single character then the size of memory occupied will be different than storing the single integer number.  The memory in our computers is organized in bytes.  A byte is the minimum amount of memory that we can manage in C.
  • 4. Syntax for declaration of a variable data_type variable_name; int var1; int std_reg_no; char std_gender;
  • 5. • Built-in data types – Fundamental data types (int, char, double, float, void, pointer) – Derived data types (array, string, structure) • Programmer-defined data types – Structure – Union – Enumeration
  • 6. Data Type keyword Description Integer Data Type int Stores the Integer Value Float Data Type float Stores the Floating Point Value Character Data Type char Stores the Single Character Value Long Data Type long Stores the Long range Integer Value Double Data Type double Stores the long range Floating Value
  • 7. Type Storage size Value range char 1 byte -128 to 127 or 0 to 255 unsigned char 1 byte 0 to 255 signed char 1 byte -128 to 127 int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 short 2 bytes -32,768 to 32,767 unsigned short 2 bytes 0 to 65,535 long 4 bytes -2,147,483,648 to 2,147,483,647 unsigned long 4 bytes 0 to 4,294,967,295 − To
  • 8. int - data type int is used to define integer numbers. float - data type float is used to define floating point numbers. char - data type char defines characters. int rollno; rollno = 5; float kilometre; kilometre = 5.6; char section; section = ‘D';
  • 9. double - data type double is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes. double Atoms; Atoms = 2500000;
  • 10. pointer-data type A pointer is a special kind of variable designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier. There are two new operators you will need to know to work with pointers. The "address of" operator '&' and the "dereferencing" operator '*'.  When you place '&' in front of a variable you will get it's address, this can be stored in a pointer vairable.  When you place an '*' in front of a pointer you will get the value at the memory address pointed to.
  • 11. { int *ptr, q; /* address of q is assigned to ptr */ ptr = &q; /* display q’s value using ptr variable */ printf(“%d”, *ptr); Output: A0250 Example of pointer
  • 12.  An array is a collection of values, all of the same type, stored contiguously in memory.  An array of size N is indexed by integers from 0 up to and including N-1.  There are also "arrays of unspecified size" where the number of elements is not known by the compiler. Here is a brief  1.One dimensional array  2. Two dimensional array array
  • 13. Array (one dimensional) #include<stdio.h> int main() { int arr[5] = {10,20,30,40,50}; printf(“value of arr[0] is %d n”, arr[0]); } Output : 10 Syntax : data-type arr_name[array_size]; //or arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50; 0 1 2 3 4 4 5 3 1 9
  • 14. Array (two dimensional) int arr[2][2] = {10,20,30,40}; printf(“value of arr[%d] [%d] : n”,arr[1][0]); Output : 30 syntax : data_type array_name[num_of_rows][num_of_column] // or arr[0][0] = 10; arr[0][1] = 20; arr[1][0] = 30; arr[1][1] = 40; 0 1 0 10 20 1 30 40
  • 15. To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Given below is an example to get the size of int type on any machine #include<stdio.h> #include<limits.h> int main() { printf("Storage size for int : %d n", sizeof(int)); return 0; } sizeof(type)
  • 16. Typecasting concept in C language is used to modify a variable from one date type to another data type. New data type should be mentioned before the variable name or value in brackets which to be typecast. #include <stdio.h> int main () { float x; x = (float) 7/5; printf("%f",x); } Output: 1.400000
  • 17. S.no Typecast function Description 1 atof() Converts string to float 2 atoi() Converts string to int 3 atol() Converts string to long 4 itoa() Converts int to string 5 ltoa() Converts long to string