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

What's hot

Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 

What's hot (20)

C++ data types
C++ data typesC++ data types
C++ data types
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Data types
Data typesData types
Data types
 
Data types in C
Data types in CData types in C
Data types in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
 
Arraysincv109102017 180831194256
Arraysincv109102017 180831194256Arraysincv109102017 180831194256
Arraysincv109102017 180831194256
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
Array
ArrayArray
Array
 
Buffersdirectx
BuffersdirectxBuffersdirectx
Buffersdirectx
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & Strings
 
Primitive data types
Primitive data typesPrimitive data types
Primitive data types
 
Data types
Data typesData types
Data types
 

Similar to Programming Fundamentals lecture 6

variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
atifmugheesv
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 

Similar to Programming Fundamentals lecture 6 (20)

Data types
Data typesData types
Data types
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
Data types in C
Data types in CData types in C
Data types in C
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
C tutorial
C tutorialC tutorial
C tutorial
 
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
 
Computer programming 2 Lesson 5
Computer programming 2  Lesson 5Computer programming 2  Lesson 5
Computer programming 2 Lesson 5
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
About size_t and ptrdiff_t
About size_t and ptrdiff_tAbout size_t and ptrdiff_t
About size_t and ptrdiff_t
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Arrays
ArraysArrays
Arrays
 

More from REHAN IJAZ

Project code for Project on Student information management system
Project code for Project on Student information management systemProject code for Project on Student information management system
Project code for Project on Student information management system
REHAN IJAZ
 

More from REHAN IJAZ (14)

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

Recently uploaded

RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
Atif Razi
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 

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