From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using pointers in structures - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Using pointers in structures
- [Instructor] Structures and pointers dance together in two ways. The first is to have a member of a structure be a pointer, and the second is to have the entire structure be a pointer. In this code, the person structure declared line seven has a pointer member, name. Like any pointer variable, it holds the location of an address in memory, in this instance, to a character or string. At line 16, storage space is allocated for the name member of the you structure. The number of bytes requested is equal to the length of the string in buffer, plus one for the null character. The allocated address is saved in the name member of the person structure variable you, at line 23. The dot notation is the same as for any other structure member. As a pointer, name must be initialized, or in this instance, memory assigned, but the notation in the structure is the same, a dot. Build and run. And I'll type my name and lie about my age. There you go, works. In this exercise file, the person structure…
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
-
-
-
-
-
Understanding pointers3m 19s
-
Using pointers to manipulate data2m 28s
-
Doing pointer math2m 57s
-
Comparing arrays and pointers3m 55s
-
Allocating storage3m 15s
-
Working with a pointer array3m 38s
-
Using pointers in structures3m 30s
-
Passing pointers to functions2m 57s
-
Returning pointers2m 39s
-
Challenge: Create a pointer array54s
-
Solution: Create a pointer array2m 23s
-
-
-
-