Lesson 1
Lesson 1
Comments
– Text surrounded by /* and */ is ignored by computer
– Used to describe program
#include <stdio.h>
– Preprocessor directive
• Tells computer to load contents of a certain file
– <stdio.h> allows standard input/output operations
A Simple C Program, Cont.
int main()
– C programs contain one or more functions,
exactly one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer
value
– Braces ({ and }) indicate a block
• The bodies of all functions must be contained in
braces
2.2 A Simple C Program:
Printing a Line of Text
Return 0;
– A way to exit a function
– Return 0, in this case, means that the
program terminated normally
Running the Program on Linux
With gcc
Use emacs, vi, or some other text editor to
type in and save program. Good idea to:
– Name program something meaningful
– Establish conventions for naming
– Add a .c suffix to the name
Compile program
– gcc hello.c [-o whatever]
Running on Linux
This produces the executable named whatever, or
a.out by default.
Type executable name to run.
– Examples.
• a.out.
• whatever.
• ./a.out.
• Etc.
Note: linker will be required when our programs
become more sophisticated – not necessary now.
Second C Program