Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

chapter1: use int main (void) as suggested by desrt.

  • Loading branch information...
commit 34f93846bfab943695b40e9f8eef2bf9e578bc7c 1 parent 46b8f48
@chergert authored
Showing with 22 additions and 6 deletions.
  1. +22 −6 book/chapter1.tex
View
28 book/chapter1.tex
@@ -23,9 +23,11 @@ \section{Hello, World!}
\begin{code}{hello.c}
#include <stdio.h>
-main ()
+int
+main (void)
{
printf ("Hello, World!\n");
+ return 0;
}
\end{code}
@@ -35,7 +37,7 @@ \section{Hello, World!}
machine code is what can be executed by your computer.
\begin{Terminal}
-cc hello.c
+cc hello.c -Wall
\end{Terminal}
If everything worked, the \file{cc} command will exit silently and a new
@@ -108,10 +110,14 @@ \section{Integers}
\begin{code}{answer.c}
#include <stdio.h>
-main ()
+int
+main (void)
{
int answer = 42;
+
printf ("The answer is %d, but what is the question?\n", answer);
+
+ return 0;
}
\end{code}
@@ -159,12 +165,15 @@ \section{Multiplication}
\begin{code}{multiply.c}
#include <stdio.h>
-main ()
+int
+main (void)
{
int a = 42;
int b = 32;
printf ("%d * %d = %d\n", a, b, a * b);
+
+ return 0;
}
\end{code}
@@ -225,12 +234,15 @@ \section{Addition, Subtraction, Division and Modulus}
\begin{code}{divide.c}
#include <stdio.h>
+int
main ()
{
int a = 221;
int b = 13;
printf ("%d / %d = %d\n", a, b, a / b);
+
+ return 0;
}
\end{code}
@@ -270,12 +282,15 @@ \section{Addition, Subtraction, Division and Modulus}
\begin{code}{modulus.c}
#include <stdio.h>
-main ()
+int
+main (void)
{
int a = 42;
int b = 32;
printf ("%d %% %d = %d\n", a, b, a % b);
+
+ return 0;
}
\end{code}
@@ -296,7 +311,8 @@ \section{Student Exercise}
\begin{code}{student1.c}
#include <stdio.h>
-main ()
+int
+main (void)
{
int a;
int b;
Please sign in to comment.
Something went wrong with that request. Please try again.