Permalink
Browse files

more work on content.

  • Loading branch information...
1 parent 9555ce7 commit 9db6e2c37aa7ad6b053ac8537ee976b9995d8826 @chergert committed Oct 29, 2012
Showing with 28 additions and 21 deletions.
  1. +28 −21 chapters/chapter1.tex
View
@@ -103,7 +103,10 @@ \section{Hello, World}
perform this task.
Open a terminal and navigate to the directory where you saved \file{hello.c}.
-Compile the source code into a program using the following command.
+Compile the source code into a program using the following command. The options
+\verb|-Wall -Werror| tells the compiler to be very strict about what it
+compiles. This helps catch bugs early. The option \verb|-o hello| tells the
+compiler to place the compiled program in a file named \file{hello}.
\begin{Terminal}
gcc -Wall -Werror -o hello hello.c
@@ -149,12 +152,12 @@ \section{Anatomy}
later chapter. Do not worry if this seems mysterious, we will cover it in detail
in a later chapter.
-After the line defining our function \ident{main}, we have a \verb|{|. This
+After the line defining our function \verb|main|, we have a \verb|{|. This
denotes the beginning of the body of the function. There is a corresponding
\verb|}| at the end of the function. Inside of these curly braces is the crux
of our program.
-\verb|printf ("Hello, World!\n")| is a function call to the \ident{printf}
+\verb|printf ("Hello, World!\n")| is a function call to the \verb|printf|
function (part of the \ident{stdio} library). You can tell it is a function call
because the function name is followed by a parenthesized argument list. In this
case, our function call has a single argument, \verb|"Hello, World!\n"|.
@@ -166,11 +169,11 @@ \section{Anatomy}
end of this string you see \verb|\n|. This means that the string should contain
a line break at the end of it.
-We denote the end of a \ident{statement} in C with a semicolon (\ident{;}).
-What exactly a \ident{statement} is will be vague for now, but it will become
+We denote the end of a \verb|statement| in C with a semicolon (\verb|;|).
+What exactly a \verb|statement| is will be vague for now, but it will become
clear as we continue.
-\section{Integers}
+\section{Variables}
Writing a Hello World program is always fun in a new language, but it wont
exactly win us any awards. Lets try to print out some interesting numbers
@@ -205,32 +208,36 @@ \section{Integers}
Answer is 42, what's the question?
\end{Terminal}
-Since we have covered the anatomy of the \ident{main} function earlier in this
-chapter, lets skip to the three lines inside the body of the function. Remember
+Since we have covered the anatomy of the \verb|main| function earlier in this
+chapter, let's skip to the three lines inside the body of the function. Remember
that these are the lines inside of the curly braces \verb|{| and \verb|}|.
+In Figure ~\ref{fig:assignment} we have the dissection of the first line.
+This line declares a new variable named \verb|a| of the type \verb|int|.
+Variables are always defined in the format \verb|type name| optionally
+followed by \verb|= value| and then \verb|;|.
+
\begin{figure}
\centering
\input{chapter1_fig1}
\caption{Variable assignment}
+ \label{fig:assignment}
\end{figure}
-Lets look at the first line, \verb|int a = 42;|. This line declares a new
-variable named \verb|a| of the type \verb|int|. Variables are always
-defined in the format \verb|type| followed by \verb|name|. \verb|int| is short
-for \verb|integer|. You might remember that an integer is an "whole" number,
-such as 1, 2, or -20. There are no decimal points in an integer. So if you
-tried to store the number \verb|12.5| in an integer, it would simply be 12. The
-second half of this statement, \verb|= 42| initialized the variable
-\verb|a| to the value \verb|42|.
+\verb|int| is short for \verb|integer|. You might remember that an integer is
+an "whole" number, such as 1, 2, or -20. There are no decimal points in an
+integer. So if you tried to store the number \verb|12.5| in an integer, it
+would simply be 12. The second half of this statement, \verb|= 42| initialized
+the variable \verb|a| to the value \verb|42|.
The second line should look familiar. It again is calling the \verb|printf|
function. However, this time there are two arguments. We will cover this in
more detail in a later chapter, but there are a few important things to take
-from this example. First, notice the comma \verb|,| used to separate the
-two arguments provided to \verb|printf|. In C, arguments are separated by
-commas. Also, note the \verb|%d| inside of the first parameter. This is a
-magic value that \verb|printf| will replace with the value of the second
-parameter.
+from this example. First, notice the comma \verb|,| used to separate the two
+arguments provided to \verb|printf|. In C, arguments are separated by commas.
+Also, note the \verb|%d| inside of the first parameter. This is a magic key
+that \verb|printf| will replace with the value of the second parameter.
+
+\section{Types}
\end{document}

0 comments on commit 9db6e2c

Please sign in to comment.