CS1050 Chapter 2: Introduction to C Programming
Does C round down or up automatically?
Down
Relational and equality operators
Higher Precedence than equality operators. These symbols are specific and you must be careful not to reverse them (using => is wrong, using >= is correct) Also, do not put a space between them like "= >"
\\
Insert a backslash character
\"
Insert a double quote character in a string
\t
Move the cursor over to the next tab stop
\n
Position the cursor at the beginning of a new line
\a
Sound the alert/alarm bell
if
gives the program choices
Conversion specifier
in the case of %d indicates that the data should be an integer %always starts a conversion specifier
int
indicates that main returns an integer(whole number) value
;
indicates the end of a function or section of code. Seperates code in the computers mind
return 0;
indicates the program ended successfully
The one function that must be included in a program
main()
Every variable has:
name, a type and a value
Allows you to use a code that has already been used.
#include<stdio.h> tells the preprocessor to include the contents of the standard input/output header (<stdio.h>) in the program.
Start and end a comment
/* /* or // // comments are ignored by the compiler
difference between = and ==
= assigns a value to the left side based on the right == shows equality
, &(insert word variable here)
Ampersand indicates which variable you are saving the entered value into
What do Words in green represent?
Commentary
binary operators
The = operator and the + operator are called binary operators because each has two operands. The + operator's two operands are integer1 and integer2. The = operator's two operands are sum and the value of the expression integer1 + integer2.
What do the parentheses after main indicate?
The parentheses after main indicate that main is a program building block called a function
Remainder Operator
The remainder operator is an integer operator that can be used only with integer operands. The expression x % y yields the remainder after x is divided by y. Thus, 7 % 4 yields 3 and 17 % 5 yields 2.
"%" followed by a character indicates what
What the computer expect to be entered. For example "%d" indicates that you will enter an interger
destructive
Whenever a value is placed in a memory location, the value replaces the previous value in that location; thus, placing a new value into a memory location
Algorithm
a sequence of events in logical order to solve a problem
condition
a statement with a truth or false to it
if statement
allows program to make a decision based on the truth or falsity of a statement
Integer division yields
an integer result thus 7/4 will be 1
syntax error
compiler won't register the command due to an incorrect semi colon, failing to close the code, etc.
All variables must be:
defined with a name and a data type immediately after the left brace that begins the body of main before they can be used in a program. Variables also are case sensitive, can be any length, and are made from letters, digits, underscores
assignment statement
example sum = integer1 + integer2; /* assign total to sum */ calculates the sum of variables integer1 and integer2 and assigns the result to variable sum using the assignment operator =.
object program is complete and ready to be executed. For this reason, the linked program is called an
executable.
straight-line form
expressions such as "a divided by b" must be written as a/b so that all operators and operands appear in a straight line.
C follows pemdas rules
parenthese first etc move left to right
instructs the computer to perform an action, namely to print on the screen the string of characters marked by the quotation marks.
printf("")
Function that will read your user input ( is found in stdio.h)
scanf
Prompt
tells the user to take a specific action.
operands
what is being added, subtracted, etc
<=
x is less than or equal to y
!=
x!=y x is not equal to y
<
x<y x is less than y
==
x==y x is equal to y
>=
x>=y x is greater than or equal to y
>
x>y x is greater than y
Indicate a block of code. They must balance out
{}