SlideShare a Scribd company logo
const and pointer,
typedef
2
const and Pointer
 const int *
– p is a pointer variable that can hold an address of const
integers
– Cannot assign value 9 to the variable pointed by p, because
the variable which p points to is const int
const int a = 7;
const int *p = &a; // possible
a = 8 ; // impossible
*p = 9 ; // impossible
3
const and Pointer
 const int *
– p, which is declared to point to const integers, can also hold an
address of integer type
– a can not be modified through by p, because p is declared as
const int *
• Any variable which is accessed through p is considered as const int
int a = 7;
const int *p = &a; // possible
a = 8 ; // possible
*p = 9 ; // impossible
4
const and Pointer
 int * and const int
– p, which is declared to point to normal integers, cannot hold
the address of const integers
– if it is possible, we can change the const variable through p
• Eg) *p = 8
const int a = 7;
int *p = &a; // impossible
5
const and Pointer
 int * const
– p is a const pointer variable which can point to normal
integers
– You cannot change its value because it is a const variable
– p is a const pointer variable of normal integer, so p cannot
hold the address of const integers
int a = 7, b = 8 ;
int * const p = &a; // possible
p = &b; // impossible
const int a = 7;
int * const p = &a; // impossible
6
const and Pointer
 const int * const
– p is a const pointer variable of const integers, so p can be
initialized once but cannot be changed anymore
const int a = 7, b = 8 ;
const int * const p = &a; // possible
p = &b; // impossible
*p = 6; // impossible
int a = 7, b = 8 ;
const int * const p = &a; // possible
p = &a; // impossible
*p = 6; // impossible
typedef
 Example
– Type name is too long
– Can we make it shorter?
7
unsigned short var1 ;
unsigned short var2 ;
…
ushort var1 ;
ushort var2 ;
…
typedef
 typedef
– old name can be consist of many words
– But, new name should be consist of one word.
8
typedef old name new name
typedef unsigned short ushort ;
void main()
{
ushort var1 ;
ushort var2 ;
…
}
typedef
 Example
9
typedef int Int ;
typedef Int INT ;
typedef unsigned long ulong ;
void main()
{
ulong var1 ;
Int k ;
INT m ;
…
}

More Related Content

DOCX
Unit 11 lesson 1 understanding integers & absolute value
PPSX
Budapest
PDF
10. pointer & function
PDF
CONST-- once initialised, no one can change it
PDF
Pointer in c++ part3
PPTX
Pointers in C Programming
PPT
Pointers in c
PPTX
Pointers in c v5 12102017 1
Unit 11 lesson 1 understanding integers & absolute value
Budapest
10. pointer & function
CONST-- once initialised, no one can change it
Pointer in c++ part3
Pointers in C Programming
Pointers in c
Pointers in c v5 12102017 1

Similar to 12 1. const pointer, typedef (20)

PPTX
Pointers in c language
PDF
Chapter 2 - Introduction to Pointer Variables - Student.pdf
PPT
Advanced C programming
PPT
Computer Programming (C++)Pointers and Arrays
PPTX
Pointer in C and its significance, Relationship between pointers and memory a...
DOCX
08-Pointers.docx An array is a linear data structure
PPTX
Pointers in C
PDF
Pointers by: Professor Lili Saghafi
PPT
Pointer introduction day1
PPTX
Lecture 7_Pointer.pptx FOR EDUCATIONAL PURPOSE
PPT
pointers CP Lecture.ppt
PPT
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
PDF
Pointers-Computer programming
PPT
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
PPT
pointer, structure ,union and intro to file handling
PPT
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
PPT
pointer, structure ,union and intro to file handling
PPTX
COM1407: Working with Pointers
PPT
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
PPT
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Pointers in c language
Chapter 2 - Introduction to Pointer Variables - Student.pdf
Advanced C programming
Computer Programming (C++)Pointers and Arrays
Pointer in C and its significance, Relationship between pointers and memory a...
08-Pointers.docx An array is a linear data structure
Pointers in C
Pointers by: Professor Lili Saghafi
Pointer introduction day1
Lecture 7_Pointer.pptx FOR EDUCATIONAL PURPOSE
pointers CP Lecture.ppt
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Pointers-Computer programming
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
COM1407: Working with Pointers
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Ad

More from 웅식 전 (20)

PDF
15 3. modulization
PDF
15 2. arguement passing to main
PDF
14. fiile io
PDF
13. structure
PDF
12 2. dynamic allocation
PDF
12 1. multi-dimensional array
PDF
11. array & pointer
PDF
9. pointer
PDF
7. variable scope rule,-storage_class
PDF
6. function
PDF
5 2. string processing
PDF
5 1. character processing
PDF
15 1. enumeration, typedef
PDF
4. loop
PDF
3 2. if statement
PDF
3 1. preprocessor, math, stdlib
PDF
2 3. standard io
PDF
2 2. operators
PDF
2 1. variables & data types
PDF
Goorm ide 교육용버전 for skku(학생)
15 3. modulization
15 2. arguement passing to main
14. fiile io
13. structure
12 2. dynamic allocation
12 1. multi-dimensional array
11. array & pointer
9. pointer
7. variable scope rule,-storage_class
6. function
5 2. string processing
5 1. character processing
15 1. enumeration, typedef
4. loop
3 2. if statement
3 1. preprocessor, math, stdlib
2 3. standard io
2 2. operators
2 1. variables & data types
Goorm ide 교육용버전 for skku(학생)
Ad

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
Machine Learning_overview_presentation.pptx
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25-Week II
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf

12 1. const pointer, typedef

  • 2. 2 const and Pointer  const int * – p is a pointer variable that can hold an address of const integers – Cannot assign value 9 to the variable pointed by p, because the variable which p points to is const int const int a = 7; const int *p = &a; // possible a = 8 ; // impossible *p = 9 ; // impossible
  • 3. 3 const and Pointer  const int * – p, which is declared to point to const integers, can also hold an address of integer type – a can not be modified through by p, because p is declared as const int * • Any variable which is accessed through p is considered as const int int a = 7; const int *p = &a; // possible a = 8 ; // possible *p = 9 ; // impossible
  • 4. 4 const and Pointer  int * and const int – p, which is declared to point to normal integers, cannot hold the address of const integers – if it is possible, we can change the const variable through p • Eg) *p = 8 const int a = 7; int *p = &a; // impossible
  • 5. 5 const and Pointer  int * const – p is a const pointer variable which can point to normal integers – You cannot change its value because it is a const variable – p is a const pointer variable of normal integer, so p cannot hold the address of const integers int a = 7, b = 8 ; int * const p = &a; // possible p = &b; // impossible const int a = 7; int * const p = &a; // impossible
  • 6. 6 const and Pointer  const int * const – p is a const pointer variable of const integers, so p can be initialized once but cannot be changed anymore const int a = 7, b = 8 ; const int * const p = &a; // possible p = &b; // impossible *p = 6; // impossible int a = 7, b = 8 ; const int * const p = &a; // possible p = &a; // impossible *p = 6; // impossible
  • 7. typedef  Example – Type name is too long – Can we make it shorter? 7 unsigned short var1 ; unsigned short var2 ; … ushort var1 ; ushort var2 ; …
  • 8. typedef  typedef – old name can be consist of many words – But, new name should be consist of one word. 8 typedef old name new name typedef unsigned short ushort ; void main() { ushort var1 ; ushort var2 ; … }
  • 9. typedef  Example 9 typedef int Int ; typedef Int INT ; typedef unsigned long ulong ; void main() { ulong var1 ; Int k ; INT m ; … }