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

Using pointers in structures - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

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…

Contents