SlideShare a Scribd company logo
DATA TYPES
in
C Programming
1
Engr. Qazi Shahzad Ali
Kyungpook National University, South Korea
Four Types of Data
1- Fundamental Data
Types
4- User Defined Data
Types
2- Data Type Modifiers
3- Derived Data Types
2
1- Fundamental Data Types
1.1- Integer
1.2- Character
1.4- Double
1.5- Void
1.3- Float
FUNDAMENTAL DATA TYPES ARE THOSE
THAT ARE NOT COMPOSED OF OTHER
DATA TYPES
3
2- Data type modifiers
2.1- Integer Type
Modifiers
2.2- Character Type
Modifiers
2.3- Floating-point Modifiers
1-They change some properties
of the data type
2-The modifiers define the
amount of storage allocated to
the variable. Like short, double,
long
4
3- Derived Data Types
3.1- Arrays
3.3- Pointers
3.4- References
3.5- Constants
3.2- Functions
5
4- User Defined Derived Data
Types
4.1- Class
4.2- Structure
4.3- Union
4.4- Enumeration
6
Web link for study of Enumeration
http://cplus.about.com/od/introductiontoprogramming/p/enumeration.htm
The Decimal & Binary Number System
Binary Decimal
0000 0 max number that can be represent by= 2n -1
0001 1 n= number of bits
0010 2 for Example if we use 1 bit then we can represent only 0 &
0011 3 1 decimal number, if 2 bit then 2 and 3, if 3 bit then max
0100 4 up to 7 (23-1=8-1=7), Similarly if we use 8 bits in case of
0101 5 “char data type” then max (28-1=256-1=255),similarly in
0110 6 case of signed 1 bit out of 8 bits are used for plus or minus
0111 7 (0 for +, & 1 for -) so (Max27-1=128-1=127) & (Min-27=-128),
1000 8
1001 9
7
Name Description Size* Range*
char Character or small integer. 1byte
signed: -128 to 127
unsigned: 0 to 255
short int (short) Short Integer. 2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
long int (long) Long integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
float Floating point number. 4bytes 10 -38 to 1038 (~7 digits)
double
Double precision floating
point number.
8bytes 10 -308 to 10308 (~15 digits)
long double
Long double precision
floating point number.
10bytes 10 -4932 to 104932 (~19 digits)
8
Integer Modifier
TYPE APPROXIMAT
E SIZE
MINIMAL RANGE
SHORT 2 -32768 to 32767
UNSIGNED SHORT 2 0 to 65,535
SIGNED SHORT 2 Same as short
INT 2 -32768 to 32767
UNSIGNED INT 2 0 to 65,535
SIGNED INT 2 Same as int
LONG 4 -2,147,483,648 TO 2,147,483,647
UNSIGNED LONG 4 0 to 4,294,967,295
SIGNED LONG 4 Same as long
Note: The prefix signed makes the integer type hold negative values also.
Unsigned makes the integer not to hold negative values.
9
Char Modifier
TYPE APPROXIMATESIZE MINIMALRANGE
CHAR 1 -128 to 127
UNSIGNED CHAR 1 0 to 255
SIGNED CHAR 1 Same as char
Floating Point Modifier
TYPE APPROXIMATE SIZE DIGITS OF
PRECISION
FLOAT 4 7
DOUBLE 8 15
LONG DOUBLE 10 19
10
How to declare them
{
int Count;
Count = 5;
}
{
float Miles;
Miles = 5.6;
}
{
char Letter;
Letter = 'x';
}
Integer Declaration:
Float Declaration:
Character Declaration:
11
Signedness
• If signed, the most significant bit designates a positive or negative value leaving
the remaining bits to be used to hold a designated value. Unsigned integers can
only take non-negative values (positive or zero), while signed integers (default) can
take both positive and negative values.
• An unsigned character, depending on the code page, might access an extended
range of characters from 0 → +255, instead of that accessible by a signed char
from −128 → +127, or it might simply be used as a small integer. The standard
requires char, signed char, unsigned char to be different types. Since most
standardized string functions take pointers to plain char, many C compilers
correctly complain if one of the other character types is used for strings passed to
these functions
 unsigned int x;
 signed int y;
 int z; /* Same as "signed int" */
 unsigned char grey;
 signed char white;
12
INTEGER DATA TYPE
Integers are whole numbers.
Countable like # of rooms in a house
C has 3 classes/Modifier of integer
1. short int
2. int
3. long int
13
FLOAT DATA TYPE
• Decimal/Exponential Number
• Values that are measureable like length of
room 145.25 inches
• Store memory in two parts
1. Mantissa (The value of number takes 3 bytes)
2. Exponent (Power of number takes 1 byte)
Exp: 12345 will be represented as 1.2345e4 (4 is exponent & 1.2345 is
number)
• They have two advantages
1: they can represent values between integers.
2: they can represent a much greater range of values.
14
CHARACTER DATA TYPE
• Includes every printable character on the
standard English language keyboard
• We can show ASCII code with the help of
characters
• Example of characters:
– Numeric digits: 0 - 9
– Lowercase/uppercase letters: a - z and A - Z
– Space (blank)
– Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
15
DOUBLE DATA TYPE
• The data type double is also used for
handling floating-point numbers. But it is
treated as a distinct data type because, it
occupies twice as much memory as type
float, and stores floating-point numbers
with much larger range and precision. It is
slower that type float.
16
VOID DATA TYPE
• It specifies an empty set of values. It is
used as the return type for functions that
do not return a value. No object of type
void may be declared.
• It is used when program or calculation
does not require any value but the syntax
needs it.
17
C-Software Tools
In order to write a C program you will need:
• An Editor - Something to write code in.
• A Compiler - Converts the code into Machine
Language (object files).
• A Linker – Combines several object files into
one executable (written in Machine
Language).
• A Debugger – Provides supervised execution
of the code.
18
• A token is a language element that can be used in
forming higher level language constructs
• Equivalent to a ‘word’ in English language
• Several types of tokens can be used to build a
higher level C language construct such as
expressions and statements
• There are 6 kinds of tokens in C:
– Reserved words (keywords)
– Identifiers
– Constants
– String literals (constant)
– Punctuators
– Operators
Token
19
Reserved Words/Keywords
• Keywords that identify language entities such as
statements, data types, language attributes, etc.
• Have special meaning to the compiler
• cannot be used as identifiers/variable in our
program.
• Should be typed in lowercase.
• White in color
• Total numbers=32
• Example: const, double, int, main, void, while, for,
else (etc..)
20
Identifiers
• Words used to represent certain program
entities (program variables, function names,
etc).
• Example:
– int my_name;
• my_name is an identifier used as a program variable
– void CalculateTotal(int value)
• CalculateTotal is an identifier used as a function name
21
Punctuators (separators)
• Symbols used to separate different parts of the C
program.
• These punctuators include:
– [ ] ( ) { } , ; “: * #
• Usage example:
22
void main (void)
{
int num=10;
printf (“%d”,num);
}
C Constants
Primary Constants
Integer Constant,
Real Constant,
Character
Constant
Secondary
Constants
Array
Pointer
Structure
Union
Enum.etc
23
Constants
• Entities that appear in the program code as fixed
values.
• 3 types of Primary constants:
– Integer constants
• Positive or negative whole numbers with no fractional part
• Example:
– const int MAX_NUM = 10;
– const int MIN_NUM = -90;
– Floating-point constants
• Positive or negative decimal numbers with an integer part, a
decimal point and a fractional part
• Example:
– const double VAL = 0.5877e2; (stands for 0.5877 x 102)
– Character constants
• A single character enclosed in a single inverted commas
• Example:
– const char letter = ‘n’;
– const char number = ‘1’; 24
String Literal (Constant)
• A sequence of Character consisting of
Alphabets,didgits,and special character in
double quotation mark is call String Constant
Example “Pakistan” and “Lahore-58900”
25
Const Qualifier
• The data that follow the keyword “const” cannot
change its value during execution of program.
This can be replaced by Define directive
Example : const float p=3.14
Alphabets Words Sentences Paragraphs
Alphabets
Digits
Special
Symbols
Constants
Variables
Keywords
Instructions Program
Steps in learning English Language
Steps in learning C Language
26
C Development Environment
DiskPhase 2 :
Preprocessor
program
processes the
code.
DiskCompilerPhase 3 :
Compiler
creates object
code and stores
it on Disk.
Preprocessor
DiskLinkerPhase 4 :
Linker links object
code with libraries,
Creates and
stores it on Disk.
EditorPhase 1 :
Program is
created in the
Editor and
stored on Disk.
Disk
27
LoaderPhase 5 :
:
.
Primary
Memory
Loader puts
Program in
Memory
C P UPhase 6 :
:
.
Primary
Memory
CPU takes each
instruction and
executes it, storing
new data values as
the program executes.
28
From code to executables
Electrical.cpp
Electrical.obj
Electrical.exe
Electrical.bkp
Compiler
Linker
SaveSource File
cs.LIB
Library Files
29
C Development system
1.IDE( Integrated Development Environment)
2.Command Line Development System
C Directories
• TC = The Install program puts all the subdirectories and files in
this directory
• BIN=Executable files store in this sub-directory
• INCLUDE= Header Files (.h file extension)
• LIB=Following Files
a) Library Files
b) Run-Time Object Files
c) Math Libraries
which are combines during Linking process, are stored in this
sub-directory
30
Making An Application
Write the source code
Compile the code into
object files
Link several object files
into an executable
Run the application
We’ll focus on this
part
Don’t worry about
these parts
31
Variable names- Rules
• Should not be a reserved word like int etc..
• Should start with a letter or an
underscore(_)
• Can contain letters, numbers or
underscore.
• No other special characters are allowed
including space
• Variable names are case sensitive
– A and a are different.
32
Brackets
•< > Angle Brackets
•{ } Curly Brackets
•( ) Parenthesis
•[ ] Square Brackets
33
A Simple C Program Example
#include <stdio.h>
main()
{
printf("Programming in C is easy.");
}
Sample Program Output
Programming in C is easy.
Preprocessor
Directive
Header File
Program
Statement
Function (NOTE: no semicolon with
function)
NOTE: All commands in C must be lowercase.
34
1. program execution begins at main()
2. keywords are written in lower-case
3. statements are terminated with a semi-colon
4. text strings are enclosed in double quotes
5. printf() is actually a function (procedure) in C
that is used for printing variables and text
6. The text appears in double quotes "", it is
printed without modification. There are some
exceptions however.
Summary of major points
35
Preprocessor Directives
• The first thing to be checked by the compiler.
• Starts with ‘#’.
• Tell the compiler about specific options that it
needs to be aware of during compilation.
• There are a few compiler directives. But only 2 of
them will be discussed here.
– #include <stdio.h>
• Tell the compiler to include the file stdio.h during
compilation
• Anything in the header file is considered a part of the
program
– #define VALUE 10
• Tell the compiler to substitute the word VALUE with 10
during compilation
36
Header Files
• Messages to Compiler called compiler
directives
• “.h” file extension
• Tell the compiler about definition of words or
phrases used in program
• Have prototype for library function in order to
avoid program error.
Examples:
• stdio.h →(Standard Input/output)
• conio.h →(Console Input/output)
• iostream →(Input Output Stream)
37
Header files (Cont’d)
• The files that are specified in the include
section is called as header file
• These are precompiled files that has some
functions defined in them
• We can call those functions in our program
by supplying parameters
38
Four types of Header Files:
stdio.h
conio.h
ctype.h
math.h
39
Stdio.h (Standard Input/output )
40
conio.h (console input/output)
41
Math.h
42
ctype .h
43
main () Functions
• A C program consists of one or more functions
that contain a group of statements which perform
a specific task.
• C program must at least have one function: the
function main.
• The C programs starting point is identified by the
word main()
• This informs the computer as to where the
program actually starts. The Parenthesis () that
follow the keyword main indicate that there are
no arguments supplied to this program (this will
be examined later on).
• The two braces, { and }, signify the begin and
end segments of the program.
44
main function (Cont’d)
• This is the entry point of a program
• When a file is executed, the start point is
the main function
• From main function the flow goes as per
the programmers choice.
• There may or may not be other functions
written by user in a program
• Main function is compulsory for any c
program
45
Statements
• A specification of an action to be taken by the
computer as the program executes.
• In the previous example the line that terminate with
semicolon ‘;’ is a statement.
– printf ("Programming in C is easy.");
• If there are more than one line then each line is a
statement.
46
Define & Declaration
• Declaration: specifies the type of a variable.
– Example: int local_var;
• Definition: assigning a value to the declared
variable.
– Example: local_var = 5;
• A variable can be declared globally or locally.
• A globally declared variable can be accessed
from all parts of the program.
• A locally declared variable can only be
accessed from inside the function in which
the variable is declared.
47
Example of Define & Declaration:
#include <stdio.h>
#define VALUE 10
int global_var;
void main (void)
{
/* This is the beginning of the program */
int local_var;
local_var = 5;
global_var = local_var + VALUE;
printf (“Total sum is: %dn”, global_var); // Print out the result
}
} Preprocessor
directive
Global variable declaration Comments
Local variable declaration
Variable definition
48
Comments writing in C
language ‘//’ & ‘/*’ ‘*/’
• Explanations or annotations that are included
in a program for documentation and
clarification purpose.
• Completely ignored by the compiler during
compilation and have no effect on program
execution.
• Starts with ‘/*’ and ends with ‘*/’
• Some compiler support comments starting
with ‘//’
49
THANK YOU
50
Ad

More Related Content

What's hot (20)

constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
CGC Technical campus,Mohali
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
C keywords and identifiers
C keywords and identifiersC keywords and identifiers
C keywords and identifiers
Akhileshwar Reddy Ankireddy
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
Dipesh Panday
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
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++
Neeru Mittal
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
Character set of c
Character set of cCharacter set of c
Character set of c
Chandrapriya Rediex
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Prof. Dr. K. Adisesha
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
Saad Sheikh
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
C program
C programC program
C program
AJAL A J
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
Dipesh Panday
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
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++
Neeru Mittal
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
Saad Sheikh
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 

Similar to Data Type in C Programming (20)

programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
FatimaZafar68
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
INTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c languageINTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c language
GOKULKANNANMMECLECTC
 
Module_1_Introduction-to-Problem-Solving.pdf
Module_1_Introduction-to-Problem-Solving.pdfModule_1_Introduction-to-Problem-Solving.pdf
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
marvellous2
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Mahfuzur Rahman
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
Widad Jamaluddin
 
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
sanatahiratoz0to9
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
Mangala R
 
introduction to programming using ANSI C
introduction to programming using ANSI Cintroduction to programming using ANSI C
introduction to programming using ANSI C
JNTUK KAKINADA
 
Unit ii
Unit   iiUnit   ii
Unit ii
sathisaran
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
FatimaZafar68
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
INTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c languageINTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c language
GOKULKANNANMMECLECTC
 
Module_1_Introduction-to-Problem-Solving.pdf
Module_1_Introduction-to-Problem-Solving.pdfModule_1_Introduction-to-Problem-Solving.pdf
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
sanatahiratoz0to9
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
Mangala R
 
introduction to programming using ANSI C
introduction to programming using ANSI Cintroduction to programming using ANSI C
introduction to programming using ANSI C
JNTUK KAKINADA
 
Ad

Recently uploaded (20)

Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Ad

Data Type in C Programming

  • 1. DATA TYPES in C Programming 1 Engr. Qazi Shahzad Ali Kyungpook National University, South Korea
  • 2. Four Types of Data 1- Fundamental Data Types 4- User Defined Data Types 2- Data Type Modifiers 3- Derived Data Types 2
  • 3. 1- Fundamental Data Types 1.1- Integer 1.2- Character 1.4- Double 1.5- Void 1.3- Float FUNDAMENTAL DATA TYPES ARE THOSE THAT ARE NOT COMPOSED OF OTHER DATA TYPES 3
  • 4. 2- Data type modifiers 2.1- Integer Type Modifiers 2.2- Character Type Modifiers 2.3- Floating-point Modifiers 1-They change some properties of the data type 2-The modifiers define the amount of storage allocated to the variable. Like short, double, long 4
  • 5. 3- Derived Data Types 3.1- Arrays 3.3- Pointers 3.4- References 3.5- Constants 3.2- Functions 5
  • 6. 4- User Defined Derived Data Types 4.1- Class 4.2- Structure 4.3- Union 4.4- Enumeration 6 Web link for study of Enumeration http://cplus.about.com/od/introductiontoprogramming/p/enumeration.htm
  • 7. The Decimal & Binary Number System Binary Decimal 0000 0 max number that can be represent by= 2n -1 0001 1 n= number of bits 0010 2 for Example if we use 1 bit then we can represent only 0 & 0011 3 1 decimal number, if 2 bit then 2 and 3, if 3 bit then max 0100 4 up to 7 (23-1=8-1=7), Similarly if we use 8 bits in case of 0101 5 “char data type” then max (28-1=256-1=255),similarly in 0110 6 case of signed 1 bit out of 8 bits are used for plus or minus 0111 7 (0 for +, & 1 for -) so (Max27-1=128-1=127) & (Min-27=-128), 1000 8 1001 9 7
  • 8. Name Description Size* Range* char Character or small integer. 1byte signed: -128 to 127 unsigned: 0 to 255 short int (short) Short Integer. 2bytes signed: -32768 to 32767 unsigned: 0 to 65535 int Integer. 2bytes signed: -32768 to 32767 unsigned: 0 to 65535 long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float Floating point number. 4bytes 10 -38 to 1038 (~7 digits) double Double precision floating point number. 8bytes 10 -308 to 10308 (~15 digits) long double Long double precision floating point number. 10bytes 10 -4932 to 104932 (~19 digits) 8
  • 9. Integer Modifier TYPE APPROXIMAT E SIZE MINIMAL RANGE SHORT 2 -32768 to 32767 UNSIGNED SHORT 2 0 to 65,535 SIGNED SHORT 2 Same as short INT 2 -32768 to 32767 UNSIGNED INT 2 0 to 65,535 SIGNED INT 2 Same as int LONG 4 -2,147,483,648 TO 2,147,483,647 UNSIGNED LONG 4 0 to 4,294,967,295 SIGNED LONG 4 Same as long Note: The prefix signed makes the integer type hold negative values also. Unsigned makes the integer not to hold negative values. 9
  • 10. Char Modifier TYPE APPROXIMATESIZE MINIMALRANGE CHAR 1 -128 to 127 UNSIGNED CHAR 1 0 to 255 SIGNED CHAR 1 Same as char Floating Point Modifier TYPE APPROXIMATE SIZE DIGITS OF PRECISION FLOAT 4 7 DOUBLE 8 15 LONG DOUBLE 10 19 10
  • 11. How to declare them { int Count; Count = 5; } { float Miles; Miles = 5.6; } { char Letter; Letter = 'x'; } Integer Declaration: Float Declaration: Character Declaration: 11
  • 12. Signedness • If signed, the most significant bit designates a positive or negative value leaving the remaining bits to be used to hold a designated value. Unsigned integers can only take non-negative values (positive or zero), while signed integers (default) can take both positive and negative values. • An unsigned character, depending on the code page, might access an extended range of characters from 0 → +255, instead of that accessible by a signed char from −128 → +127, or it might simply be used as a small integer. The standard requires char, signed char, unsigned char to be different types. Since most standardized string functions take pointers to plain char, many C compilers correctly complain if one of the other character types is used for strings passed to these functions  unsigned int x;  signed int y;  int z; /* Same as "signed int" */  unsigned char grey;  signed char white; 12
  • 13. INTEGER DATA TYPE Integers are whole numbers. Countable like # of rooms in a house C has 3 classes/Modifier of integer 1. short int 2. int 3. long int 13
  • 14. FLOAT DATA TYPE • Decimal/Exponential Number • Values that are measureable like length of room 145.25 inches • Store memory in two parts 1. Mantissa (The value of number takes 3 bytes) 2. Exponent (Power of number takes 1 byte) Exp: 12345 will be represented as 1.2345e4 (4 is exponent & 1.2345 is number) • They have two advantages 1: they can represent values between integers. 2: they can represent a much greater range of values. 14
  • 15. CHARACTER DATA TYPE • Includes every printable character on the standard English language keyboard • We can show ASCII code with the help of characters • Example of characters: – Numeric digits: 0 - 9 – Lowercase/uppercase letters: a - z and A - Z – Space (blank) – Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc 15
  • 16. DOUBLE DATA TYPE • The data type double is also used for handling floating-point numbers. But it is treated as a distinct data type because, it occupies twice as much memory as type float, and stores floating-point numbers with much larger range and precision. It is slower that type float. 16
  • 17. VOID DATA TYPE • It specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared. • It is used when program or calculation does not require any value but the syntax needs it. 17
  • 18. C-Software Tools In order to write a C program you will need: • An Editor - Something to write code in. • A Compiler - Converts the code into Machine Language (object files). • A Linker – Combines several object files into one executable (written in Machine Language). • A Debugger – Provides supervised execution of the code. 18
  • 19. • A token is a language element that can be used in forming higher level language constructs • Equivalent to a ‘word’ in English language • Several types of tokens can be used to build a higher level C language construct such as expressions and statements • There are 6 kinds of tokens in C: – Reserved words (keywords) – Identifiers – Constants – String literals (constant) – Punctuators – Operators Token 19
  • 20. Reserved Words/Keywords • Keywords that identify language entities such as statements, data types, language attributes, etc. • Have special meaning to the compiler • cannot be used as identifiers/variable in our program. • Should be typed in lowercase. • White in color • Total numbers=32 • Example: const, double, int, main, void, while, for, else (etc..) 20
  • 21. Identifiers • Words used to represent certain program entities (program variables, function names, etc). • Example: – int my_name; • my_name is an identifier used as a program variable – void CalculateTotal(int value) • CalculateTotal is an identifier used as a function name 21
  • 22. Punctuators (separators) • Symbols used to separate different parts of the C program. • These punctuators include: – [ ] ( ) { } , ; “: * # • Usage example: 22 void main (void) { int num=10; printf (“%d”,num); }
  • 23. C Constants Primary Constants Integer Constant, Real Constant, Character Constant Secondary Constants Array Pointer Structure Union Enum.etc 23
  • 24. Constants • Entities that appear in the program code as fixed values. • 3 types of Primary constants: – Integer constants • Positive or negative whole numbers with no fractional part • Example: – const int MAX_NUM = 10; – const int MIN_NUM = -90; – Floating-point constants • Positive or negative decimal numbers with an integer part, a decimal point and a fractional part • Example: – const double VAL = 0.5877e2; (stands for 0.5877 x 102) – Character constants • A single character enclosed in a single inverted commas • Example: – const char letter = ‘n’; – const char number = ‘1’; 24
  • 25. String Literal (Constant) • A sequence of Character consisting of Alphabets,didgits,and special character in double quotation mark is call String Constant Example “Pakistan” and “Lahore-58900” 25 Const Qualifier • The data that follow the keyword “const” cannot change its value during execution of program. This can be replaced by Define directive Example : const float p=3.14
  • 26. Alphabets Words Sentences Paragraphs Alphabets Digits Special Symbols Constants Variables Keywords Instructions Program Steps in learning English Language Steps in learning C Language 26
  • 27. C Development Environment DiskPhase 2 : Preprocessor program processes the code. DiskCompilerPhase 3 : Compiler creates object code and stores it on Disk. Preprocessor DiskLinkerPhase 4 : Linker links object code with libraries, Creates and stores it on Disk. EditorPhase 1 : Program is created in the Editor and stored on Disk. Disk 27
  • 28. LoaderPhase 5 : : . Primary Memory Loader puts Program in Memory C P UPhase 6 : : . Primary Memory CPU takes each instruction and executes it, storing new data values as the program executes. 28
  • 29. From code to executables Electrical.cpp Electrical.obj Electrical.exe Electrical.bkp Compiler Linker SaveSource File cs.LIB Library Files 29
  • 30. C Development system 1.IDE( Integrated Development Environment) 2.Command Line Development System C Directories • TC = The Install program puts all the subdirectories and files in this directory • BIN=Executable files store in this sub-directory • INCLUDE= Header Files (.h file extension) • LIB=Following Files a) Library Files b) Run-Time Object Files c) Math Libraries which are combines during Linking process, are stored in this sub-directory 30
  • 31. Making An Application Write the source code Compile the code into object files Link several object files into an executable Run the application We’ll focus on this part Don’t worry about these parts 31
  • 32. Variable names- Rules • Should not be a reserved word like int etc.. • Should start with a letter or an underscore(_) • Can contain letters, numbers or underscore. • No other special characters are allowed including space • Variable names are case sensitive – A and a are different. 32
  • 33. Brackets •< > Angle Brackets •{ } Curly Brackets •( ) Parenthesis •[ ] Square Brackets 33
  • 34. A Simple C Program Example #include <stdio.h> main() { printf("Programming in C is easy."); } Sample Program Output Programming in C is easy. Preprocessor Directive Header File Program Statement Function (NOTE: no semicolon with function) NOTE: All commands in C must be lowercase. 34
  • 35. 1. program execution begins at main() 2. keywords are written in lower-case 3. statements are terminated with a semi-colon 4. text strings are enclosed in double quotes 5. printf() is actually a function (procedure) in C that is used for printing variables and text 6. The text appears in double quotes "", it is printed without modification. There are some exceptions however. Summary of major points 35
  • 36. Preprocessor Directives • The first thing to be checked by the compiler. • Starts with ‘#’. • Tell the compiler about specific options that it needs to be aware of during compilation. • There are a few compiler directives. But only 2 of them will be discussed here. – #include <stdio.h> • Tell the compiler to include the file stdio.h during compilation • Anything in the header file is considered a part of the program – #define VALUE 10 • Tell the compiler to substitute the word VALUE with 10 during compilation 36
  • 37. Header Files • Messages to Compiler called compiler directives • “.h” file extension • Tell the compiler about definition of words or phrases used in program • Have prototype for library function in order to avoid program error. Examples: • stdio.h →(Standard Input/output) • conio.h →(Console Input/output) • iostream →(Input Output Stream) 37
  • 38. Header files (Cont’d) • The files that are specified in the include section is called as header file • These are precompiled files that has some functions defined in them • We can call those functions in our program by supplying parameters 38
  • 39. Four types of Header Files: stdio.h conio.h ctype.h math.h 39
  • 44. main () Functions • A C program consists of one or more functions that contain a group of statements which perform a specific task. • C program must at least have one function: the function main. • The C programs starting point is identified by the word main() • This informs the computer as to where the program actually starts. The Parenthesis () that follow the keyword main indicate that there are no arguments supplied to this program (this will be examined later on). • The two braces, { and }, signify the begin and end segments of the program. 44
  • 45. main function (Cont’d) • This is the entry point of a program • When a file is executed, the start point is the main function • From main function the flow goes as per the programmers choice. • There may or may not be other functions written by user in a program • Main function is compulsory for any c program 45
  • 46. Statements • A specification of an action to be taken by the computer as the program executes. • In the previous example the line that terminate with semicolon ‘;’ is a statement. – printf ("Programming in C is easy."); • If there are more than one line then each line is a statement. 46
  • 47. Define & Declaration • Declaration: specifies the type of a variable. – Example: int local_var; • Definition: assigning a value to the declared variable. – Example: local_var = 5; • A variable can be declared globally or locally. • A globally declared variable can be accessed from all parts of the program. • A locally declared variable can only be accessed from inside the function in which the variable is declared. 47
  • 48. Example of Define & Declaration: #include <stdio.h> #define VALUE 10 int global_var; void main (void) { /* This is the beginning of the program */ int local_var; local_var = 5; global_var = local_var + VALUE; printf (“Total sum is: %dn”, global_var); // Print out the result } } Preprocessor directive Global variable declaration Comments Local variable declaration Variable definition 48
  • 49. Comments writing in C language ‘//’ & ‘/*’ ‘*/’ • Explanations or annotations that are included in a program for documentation and clarification purpose. • Completely ignored by the compiler during compilation and have no effect on program execution. • Starts with ‘/*’ and ends with ‘*/’ • Some compiler support comments starting with ‘//’ 49