Skip to content

Commit

Permalink
Clean up some things in ex16.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedshaw committed Sep 11, 2011
1 parent c030b1d commit 10b2cd9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ex16.tex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ \chapter{Exercise 16: Structs And Pointers To Them}
\item [struct Person] This is where I'm creating a structure that
has 4 elements to describe a person. The final result is a
new compound type that let's me reference these elements all
as one, or each piece. It's similar to a row of a database
as one, or each piece by name. It's similar to a row of a database
table or an class in an OOP language.
\item[function Person\_create] I need a way to create these structures
so I've made a function to do that. Here's the important
Expand All @@ -35,7 +35,7 @@ \chapter{Exercise 16: Structs And Pointers To Them}
\item I pass to \func{malloc} the \verb|sizeof(struct Person)|
which calculates the total size of the struct, given all the
fields inside it.
\item I use \func{assert} to make sure that I got a valid
\item I use \func{assert} to make sure that I have a valid
piece of memory back from malloc. There's a special constant called
\ident{NULL} that you use to mean "unset or invalid pointer". This
\func{assert} is basically checking that malloc didn't return a
Expand Down Expand Up @@ -120,9 +120,12 @@ \section{Explaining Structures}
of expressions you would other data types.
\item This lets you pass the whole cohesive grouping to other
functions, as you did with \func{Person\_print}.
\item Finally, you can then access the individual parts of a
\item You can then access the individual parts of a
\ident{struct} by their names using \verb|x->y| if you're
dealing with a pointer.
\item There's also a way to make a struct that doesn't need
a pointer, and you use the \verb|x.y| (period) syntax
to work with it. You'll do this in the Extra Credit.
\end{enumerate}

If you didn't have \ident{struct} you'd need to figure out
Expand Down

0 comments on commit 10b2cd9

Please sign in to comment.