You are on page 1of 3

4

COP3514
I.

Chapter 2: C Fundamentals
1. Writing a Simple Program
A. Compiling and Linking
a. In order to make a program executable, there are three steps
i. Preprocessing
Preprocessor obeys the directive commands (#include).
ii. Compiling
Compiler translates the code into the object code (machine
instructions)
iii. Linking
Linker combines the object code with additional codes
b. o command (options) allows us to choose the name of the file
B. Integrated Development Environments
a. Integrated Development Environments (IDE)
i. Software package that allows us to edit, compile, link, execute, and
even debug a program without leaving the environment
2. The General Form of a Simple Program
A. C programs have the general form
a. Directives
b. Function
c. Statements
B. Directives
a. Directives state that information from libraries are to be included into
the program before it is compiled
b. C has no built-in read and write commands
i. These are included in the libraries
c. Directives always start with a # and have no semicolons or other
special markers at the end
C. Functions
a. Functions
i. Procedures or subroutines in other programming languages
ii. A series of statements that have been grouped together and given
a name
b. Some functions return values, some dont
c. Main function is the most important function in a program
i. Main functions always have a return value at the end and will
terminate
ii. The main function will still terminate without a return statement
The compiler will throw a warning
D. Statements
a. Statement
i. Command to be executed when the program run
b. Calling
i. Asking a function to perform its assigned task
E. Print Strings
a. String Literal
i. A series of characters enclosed by a set of double quotes
b. Printf
i. Displays a string literal

COP3514
ii. Does not automatically start a new line
Must ad \n to make a new line
3. Comments
A. Every program should contain identifying information
a. Program name, date written, author, purpose, etc.
B. Comments
a. Contains identifying information
b. /*starts a type of comment
i. */ ends the comment
ii. Can be extended to multiple lines
c. C99 allows // to be the beginning of a comment
i. This takes one line
4. Variable and Assignment
A. Variables
a. Storage locations
B. Types
a. Type
i. A specific of what kind of data will be held in the memory
b. For now, we will focus on 2 types:
i. Int
Can store integers values
ii. Float
Can store more larger numbers than int
Stores numbers after a decimal point
C. Declaration
a. Declare
i. Describe for the benefit of the compiler
b. To declare
i. Specify the type
ii. Name it
D. Assignment
a. Assign
i. To give a variable a value
b. Assignment is done with an =
i. Name = value;
Value is a constant
c. Before a variable is assigned, it must be declared first
d. It is best to add f to the end of a constant if the constant is a type float
e. Once a variable is assigned, it can be used to do math
i. The rights side of an assignment can be a formula involving
constants, variables, and operators
E. Printing the Value of a Variable
a. Values can be printed using the printf statement
i. The numbers need a placeholder
%d is for int variables
%f is for float variables
In order to force the program to print n digits after the
decimal, use %.nf
b. No limit to the variables that can be printed in the printf statement

COP3514
F. Initialization
a. Uninitialized
i. A variable that does not have a value either by default or not being
assigned
b. Some variables may initialize to 0, but thats not always the case
G. Printing Expressions
a. Printf can display the value of any numeric expression
5. Reading Input
A. Scanf
a. A function that obtains user input
b. Must have the data conversion type in double quotes, followed by the
variable you want the number stored as
i. Scanf(%d, &i);
Stores the value input by the user into the variable i
Same process for a float
6. Defining Names for Constants
A. Macro definition
a. Defines a constant using a directive
i. #define NUMBER value
7. Identifiers
A. Identifiers
a. Names for variables, functions, and other entities within the program
B. Legal identifiers
a. Must begin with a letter
b. Can contain underscores
c. Can use upper and lower case letters
C. C is case sensitive
D. Its common that identifiers with multiple names have underscores in
between each word to improve legibility
a. Can also upper case the first letter of the next word
E. No limit on the length of an identifier
F. Key Words
a. Key words
i. Words that have a special meaning to the compiler and therefore
cannot be used as identifiers

You might also like