Upcoming SlideShare
×

# 12 1. const pointer, typedef

916 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
916
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
7
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 12 1. const pointer, typedef

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