From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Working with pointers in structures - C Tutorial
From the course: Master C Language Pointers
Working with pointers in structures
- [Instructor] A pointer can be a structure member just like any valid variable type. In this code, two pointers dwell in the person structure: character pointer name and integer pointer age. These members are declared like any other structure variable but the asterisk operator identifies them as pointers. Storage for pointer member age is allocated at line 13. Standard structure member notation is used, my.age. And the return address is tested. The program exits if the null pointer is returned. Otherwise, at line 21 a value is assigned to the age member. The asterisk operator is used to reference the contents of the address. Dot notation is used for the age pointer structure member. At line 26, the base address of character array n is assigned to the address stored in pointer member name. The asterisk of operator isn't required as both values represent an address. And my.name doesn't need to be initialized or allocated because…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Comparing arrays and pointers3m 36s
-
(Locked)
Allocating storage3m 29s
-
(Locked)
Exploring allocation functions4m 58s
-
(Locked)
Accessing the buffer3m 41s
-
(Locked)
Working with pointers in structures2m 18s
-
(Locked)
Creating structure pointers3m 29s
-
(Locked)
Saving pointers and buffers4m 31s
-
(Locked)
Challenge: Saving and reading a record1m 6s
-
(Locked)
Solution: Saving and reading a record2m 15s
-
-
-