SlideShare a Scribd company logo
www.iies.in PH: +91 98869 20008 enquiry@iies.in
TYPEDEF IN C
www.iies.in PH: +91 98869 20008 enquiry@iies.in
• Type aliases that enhance the readability and manageability of the code can be created with
typedef. It can generate new identifiers for types that have been defined already.
• Typedef is a user-defined datatype
• The keyword is typedef
• It is used to create your own datatype
• Typedef has a lifetime and scope
Syntax:
typedef int ind;
Typedef in C
www.iies.in PH: +91 98869 20008 enquiry@iies.in
Basic Usage of typedef:
The typedef keyword in C is used to create new names (aliases) for existing data types. This
enhances readability and contributes to the code's maintainability.
Example:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
typedef with Structures:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
typedef with Pointers:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
typedef with Arrays:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
typedef for Function Pointers:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
Predefined typedef Variables in C and C++
C and C++ have several predefined typedef types that provide alternative names for existing
data types. These typedefs enhance the code's portability and readability.
Standard Integer Types (stdint.h / cstdint)
C99 introduced the <stdint.h> header, which defines fixed-width integer types using typedef.
C++ includes this as <cstdint>.
www.iies.in PH: +91 98869 20008 enquiry@iies.in
Typedef Equivalent Type Size
int8_t signed char 1 byte
uint8_t unsigned char 1 byte
int16_t short int 2 bytes
uint16_t unsigned short int 2 bytes
int32_t Int 4 bytes
uint32_t unsigned int 4 bytes
int64_t long long int 8 bytes
uint64_t unsigned long long int 8 bytes
Common Typedefs for Integer Types
www.iies.in PH: +91 98869 20008 enquiry@iies.in
Typedef Purpose
size_t Used for sizes of objects (array indexing, malloc(), etc.)
ptrdiff_t ptrdiff_t Holds the difference of two pointers
wchar_t Represents wide characters
Size-Specific Types (stddef.h)
Some important typedef types from <stddef.h>:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
size_t is an unsigned integer type that represents the sizes of objects in memory. It is commonly used for
array indexing, memory allocation, and loop counters. The actual size of size_t depends on the system
architecture:
32-bit systems: size_t typically occupies 4 bytes (unsigned integer with a size of 32 bits).
64-bit systems: size_t typically occupies 8 bytes (unsigned integer of 64 bits).
Example
size_t in C:
www.iies.in PH: +91 98869 20008 enquiry@iies.in
ptrdiff_t is a signed integer type defined in the C header. It serves to illustrate the variance
between two pointers.
Why Use ptrdiff_t?
• It ensures portability across different systems.
• It is specifically designed for pointer arithmetic.
• It prevents issues that may arise from using standard integer types for pointer differences.
Example
ptrdiff_t in C:

More Related Content

PPTX
Datatypes
PPT
cprogrammingdatatype.ppt
PPT
cprogrammingdatatypesand differentdtatypes (1).ppt
PPT
cprogrammingdatatype using clangauge(1).ppt
PPT
cprogrammingdata_type in with explanation.ppt
DOCX
Explain the importance of using the typedef keyword then write a C ++.docx
PPTX
TAPASH kumar das its my college pptasjhk
PPTX
data types in C programming
Datatypes
cprogrammingdatatype.ppt
cprogrammingdatatypesand differentdtatypes (1).ppt
cprogrammingdatatype using clangauge(1).ppt
cprogrammingdata_type in with explanation.ppt
Explain the importance of using the typedef keyword then write a C ++.docx
TAPASH kumar das its my college pptasjhk
data types in C programming

Similar to Typedef in C – Easy Explanation | IIES Bangalore (20)

PDF
cassignmentii-170424105623.pdf
PDF
introduction to programming using ANSI C
PPT
C Programming Intro.ppt
DOCX
PPTX
structured Programming Unit-2-Basic-Elements-of-C.pptx
PPTX
Programming Fundamentals lecture 6
PDF
SPL 3 | Introduction to C programming
PPTX
Data Type in C Programming
PPSX
Data type
PDF
Zaridah lecture2
PPTX
PPTX
Typedef
PDF
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
PDF
Programming in C - interview questions.pdf
PPTX
LESSON1-C_programming (1).GRADE 8 LESSONpptx
PPTX
data types in c programming language in detail
PPTX
C language
PDF
Embedded C Programming Module1 Presentation.pdf
PPTX
Basic of Structered Programming in C psd
PPTX
C Programming : data types and types of variable.pptx
cassignmentii-170424105623.pdf
introduction to programming using ANSI C
C Programming Intro.ppt
structured Programming Unit-2-Basic-Elements-of-C.pptx
Programming Fundamentals lecture 6
SPL 3 | Introduction to C programming
Data Type in C Programming
Data type
Zaridah lecture2
Typedef
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
Programming in C - interview questions.pdf
LESSON1-C_programming (1).GRADE 8 LESSONpptx
data types in c programming language in detail
C language
Embedded C Programming Module1 Presentation.pdf
Basic of Structered Programming in C psd
C Programming : data types and types of variable.pptx
Ad

More from ibrahimseo2025 (7)

PDF
Best Embedded Systems Course for Practical Learning
PDF
What Makes the Best Embedded Systems Course?
PPTX
Dynamic Memory Allocation in C Programming | IIES Guide
PPTX
Functions in C Programming: A Simple Guide | IIES Bangalore
PPTX
Pointers in C – Explained with Examples|IIES Bangalore
PPTX
Arrays in C – Beginner Friendly Guide| IIES Bangalore
PPTX
Structure in C – Complete Guide | IIES Bangalore
Best Embedded Systems Course for Practical Learning
What Makes the Best Embedded Systems Course?
Dynamic Memory Allocation in C Programming | IIES Guide
Functions in C Programming: A Simple Guide | IIES Bangalore
Pointers in C – Explained with Examples|IIES Bangalore
Arrays in C – Beginner Friendly Guide| IIES Bangalore
Structure in C – Complete Guide | IIES Bangalore
Ad

Recently uploaded (20)

PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Trump Administration's workforce development strategy
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Trump Administration's workforce development strategy
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
History, Philosophy and sociology of education (1).pptx
Weekly quiz Compilation Jan -July 25.pdf
Cell Structure & Organelles in detailed.
Paper A Mock Exam 9_ Attempt review.pdf.
What if we spent less time fighting change, and more time building what’s rig...
Module 4: Burden of Disease Tutorial Slides S2 2025
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

Typedef in C – Easy Explanation | IIES Bangalore

  • 1. www.iies.in PH: +91 98869 20008 enquiry@iies.in TYPEDEF IN C
  • 2. www.iies.in PH: +91 98869 20008 enquiry@iies.in • Type aliases that enhance the readability and manageability of the code can be created with typedef. It can generate new identifiers for types that have been defined already. • Typedef is a user-defined datatype • The keyword is typedef • It is used to create your own datatype • Typedef has a lifetime and scope Syntax: typedef int ind; Typedef in C
  • 3. www.iies.in PH: +91 98869 20008 enquiry@iies.in Basic Usage of typedef: The typedef keyword in C is used to create new names (aliases) for existing data types. This enhances readability and contributes to the code's maintainability. Example:
  • 4. www.iies.in PH: +91 98869 20008 enquiry@iies.in typedef with Structures:
  • 5. www.iies.in PH: +91 98869 20008 enquiry@iies.in typedef with Pointers:
  • 6. www.iies.in PH: +91 98869 20008 enquiry@iies.in typedef with Arrays:
  • 7. www.iies.in PH: +91 98869 20008 enquiry@iies.in typedef for Function Pointers:
  • 8. www.iies.in PH: +91 98869 20008 enquiry@iies.in Predefined typedef Variables in C and C++ C and C++ have several predefined typedef types that provide alternative names for existing data types. These typedefs enhance the code's portability and readability. Standard Integer Types (stdint.h / cstdint) C99 introduced the <stdint.h> header, which defines fixed-width integer types using typedef. C++ includes this as <cstdint>.
  • 9. www.iies.in PH: +91 98869 20008 enquiry@iies.in Typedef Equivalent Type Size int8_t signed char 1 byte uint8_t unsigned char 1 byte int16_t short int 2 bytes uint16_t unsigned short int 2 bytes int32_t Int 4 bytes uint32_t unsigned int 4 bytes int64_t long long int 8 bytes uint64_t unsigned long long int 8 bytes Common Typedefs for Integer Types
  • 10. www.iies.in PH: +91 98869 20008 enquiry@iies.in Typedef Purpose size_t Used for sizes of objects (array indexing, malloc(), etc.) ptrdiff_t ptrdiff_t Holds the difference of two pointers wchar_t Represents wide characters Size-Specific Types (stddef.h) Some important typedef types from <stddef.h>:
  • 11. www.iies.in PH: +91 98869 20008 enquiry@iies.in size_t is an unsigned integer type that represents the sizes of objects in memory. It is commonly used for array indexing, memory allocation, and loop counters. The actual size of size_t depends on the system architecture: 32-bit systems: size_t typically occupies 4 bytes (unsigned integer with a size of 32 bits). 64-bit systems: size_t typically occupies 8 bytes (unsigned integer of 64 bits). Example size_t in C:
  • 12. www.iies.in PH: +91 98869 20008 enquiry@iies.in ptrdiff_t is a signed integer type defined in the C header. It serves to illustrate the variance between two pointers. Why Use ptrdiff_t? • It ensures portability across different systems. • It is specifically designed for pointer arithmetic. • It prevents issues that may arise from using standard integer types for pointer differences. Example ptrdiff_t in C: