CPSC 1010
Typically a partially filled array
String Variable
When the next statement executed is not the next one in sequence
Transfer of control
C programs consist of pieces/modules called ________.
functions
Can capture the result of the preprocessor (will end in a .i) by compiling with the following flag:
gcc -E prog.c
Can capture the result of the assembler (will end in a .s) by compiling with the following flag:
gcc -S prog.c
code to compile program
gcc -Wall
Can capture the file containing the object code (will end in a .o) by compiling with the following flag:
gcc -c prog.c
Can capture all the intermediate files by compiling with the following:
gcc -save-temps prog.c
Reads in a line (terminated by a newline) from standard input
gets
Short signed integer type.
int , %d , %i
Give a for loop to assign the below values to list... int list[5], i;
int list[5], i; for(i=0; i<5; i++){ list[i] = 4-i; }
int values always follow
int main(void) {
Writes one character at a time
int putchar (int outChar)
C provides the following data types:
int, float, double, char, and _Bool
The loop control variable is the variable whose value controls loop ______.
repetition
result++;
result = result + 1;
How are floats stored?
scientific notation in binary, m * b^e
Find the minimum value of the list and swap it with the element at the index where it is supposed to go.
selection sort
Control structures
sequence, selection, repetition
Use looping when you want to execute a block of code ______
several times
You can use the ______ operator to find out how big different data types are.
sizeof
takes an unordered collection and makes it an ordered one.
sorting
Appends one string onto end of another
strcat(destination, source)
Three types of loops in C
while, for, do-while
Set of statements within a pair of braces
Compound statement
Branch to another location
Control flow operations
Who died of cancer at the age of 37.
Ada Lovelace
Who lived from 1815 - 1852
Ada Lovelace
Who met Charles Babbage at a dinner party at the age of 17; was intrigued by his talk about a new calculating engine (the "Analytical Engine") that he was trying to create (very few people were interested in his ideas)
Ada Lovelace
A __________ program executes automatically before the compiler's translation phase begins.
processor
x is greater than or equal to y
x >= y
Returns true if either of its conditions is true
||
Comments go _____ to what its referring to
above
storing floating-‐point numbers, i.e. values containing decimal places
float
6 decimal places
float , %f
Natural 'counting' loop
for statement
Where computer stores "what it is thinking about"
memory
creates a directory name dir_name in your current directory
mkdir dir_name
moves src_file to the folder specified by dest_path and gives it the name dest_file
mv src_file dest_dir/dest_file
renames src_file to dest_file
mv src_file dest_file
moves src_file to the folder specified by the dest_path
mv src_file dest_path
Is assembly language portable?
no
Is machine language portable?
no
If _____ overwritten, no longer a valid C-string
null
in strings theres always an end marker
null character
Manages the software and hardware on the computer
operating system
while loop is repeated
As long as condition is true, and until condition becomes false
Programmers write instructions that look almost like everyday English and contain commonly used mathematical notations.
Compilers
Call another block of code
Control flow operations
Conditionally branch
Control flow operations
Phase 1 of C
Edit
Uses return from scanf, can be fooled by invalid data
End-of-input controlled loops
Phase 5 of C
Execute
Developed at Bell Labs in the late 1960s
UNIX
used just to store the values 1 or 0
_Bool
can take on values 0 (false) and 1 (true)
_Bool data type
a += 2
a = a + 2
integral numbers, or integers -‐ -‐ numbers without decimal places
int
Two dimensional array
int a[3][4];
Reads one character at a time from a text stream
int getchar( )
kills the process you specify with the pid (process id #) which is shown when you type ps
kill -9 [pid]
Two parts of compiling
preprocessor and assembler
Leave out ______ when designing for redirection
prompts
shows a listing of processes that are running
ps
Takes a null-terminated string from memory and writes it to standard output
puts
The function ______ will generate a (pseudo) random number from 0 to RAND_MAX,
rand()
you wanted 100 numbers from 0 to 99:
rand() % 100
If you wanted 100 numbers from 1 to 100:
rand() % 100 + 1
10 - 30 (inclusive):
rand() % 21 + 10
1985 - 2016 (inclusive):
rand() % 32 + 1985
Read / Write to actual file
redirection
input from keyboard
stdin
scanf() automatically gets input from _____
stdin
The C-run time system automatically opens up 3 files (that are defined in <stdio.h>) when a program is run:
stdin, stdout, stderr
output to screen
stdout
printf() automatically sends output to _____
stdout
Hard disk drive (HDD)
storage
Long term storage
storage
x is equal to y
x == y
x is greater than y
x > y
Who produced a design for a flying machine at the age of 13.
Ada Lovelace
Who was brought up by her mother to be a mathematician and scientist to make sure she wouldn't end up a poet like her father
Ada Lovelace
Who was the daughter of the poet Lord Byron, whom she never met; her parents separated when she was 5 weeks old
Ada Lovelace
Whos plan is now regarded as the first "computer program".
Ada Lovelace
Who created the first compiler
Admiral Grace Murray Hopper
Who got B.A. Mathematics from Vassar; M.A. and Ph.D. from Yale
Admiral Grace Murray Hopper
Who lived from 1906‐1992
Admiral Grace Murray Hopper
Who was an Associate Professor of mathematics at Vassar
Admiral Grace Murray Hopper
Whos idea was that programs could be written in more English‐like statements than Assembly Language.
Admiral Grace Murray Hopper
translate assembly-language to machine language.
Assemblers
Symbolic names for both instructions and locations
Assembly language
English-like abbreviations to represent elementary operations.
Assembly languages
Expression that evaluates to true or false
Boolean Expressions
By late 1970's C had evolved to "Traditional C"
C
Evolved by Dennis Ritchie (Bell Labs) from two previous programming languages, BCPL and B
C
Hardware independent (portable)
C
Used to develop UNIX
C
Unix mediates access by processes to the:
CPU, memory, storage
CPU
Central Processing Unit
Who lived from 1791 - 1871?
Charles Babbage
Who was an English mathematician, philosopher, inventor & mechanical engineer who originated the concept of a programmable computer
Charles Babbage
End-Of-File
Ctrl-d
Machine dependent—a particular machine language can be used on only one type of computer.
Machine language
defined by its hardware design
Machine language
language that computer can directly process
Machine language
strings of numbers (ultimately reduced to 1s and 0s) that instruct computer to perform most elementary ops one at a time.
Machine language
HOW MANY TIMES TO PERFORM BUBBLE-UP?
N - 1 times
Test for multiple cases by placing if-else selection structures inside if-else selection structures.
Nested if-else structures
In use while computer is powered on (volatile)
memory
Short-term data access
memory
UNIX is an ________.
operating system
Some modern computer architectures can execute several instructions in _________.
parallel
Full names of UNIX files are _______, including directories.
pathnames
Info in storage must be loaded into memory for CPU to access it
storage
Persists when power is turned off
storage
The order in which statements are executed
Flow of control
Pool of memory used for dynamically allocated memory
Heap segment
RAM
Random Access Memory
have the user enter a special value to indicate the end of input
Sentinel-Controlled Repetition
Activation records, automatic local variables; LIFO
Stack segment
Committee formed to create a "unambiguous, machine-independent" definition (ANSI, American National Standards Institute)
Standardization
Many slight variations of C existed, and were incompatible
Standardization
Standard created in 1989, updated in 1999
Standardization
Also called code segment; machine instructions of the program
Text segment
_______ is a single file system
UNIX
What if we want to print the number of passing scores (scores >= 70)?
Use if
What if we want to print the number of passing scores (scores >= 70) and the number of failing scores?
Use if-else
A _______ links the object code with the code for the missing functions to produce an ____________.
linker, executable program
The _______, takes the executable image from disk and transfers it to memory.
loader
(x < 7) && (y > 3)
logical expression
19 decimal places
long double, %Lf
list all contents in your current directory
ls
The language made up of binary-coded instructions that is used directly by the computer
machine language
CPU can access easily
memory
7 < 5, a + b > 6
relational expressions
result--;
result = result - 1;
always end a program with
return 0; }
deletes the directory named dir_name
rm -rf dir_name
deletes the file named file_name
rm file_name
deletes the directory named dir_name if it is empty
rmdir dir_name
captures input from standard input (stdin) and stores it in the variable specified in the argument(s) after the comma
scanf()
To seed a random num gen include the following line of code in your program, somewhere above the rand() function call:
srand((int)time(0));
You can seed the random number generator with the _______ function using something other than 1.
srand()
command to get onto terminal
ssh <userid>@<machinename>.computing.clemson.edu
Can be very useful for displaying error messages to users or for debugging purposes, or just whenever you want to have certain output not be written to a file.
stderr
When specifying ______ in a fprintf() statement, error messages will be sent to the screen even when redirecting other output to a file.
stderr
error messages always sent to the screen
stderr
== with strings
strcmp(string1, string2), >,==,< 0
= with strings
strcpy(destination, source)
An array of characters
string
String Length
strlen
Consists of a series of case labels and an optional default case
switch
Useful when variable or expression is tested for multiple values
switch
y[2] is what element in an array
third
Exit pico, saving buffer.
control x
copies src_file to dest_file
cp src_file dest_file
copies src_file to the folder specified by dest_path
cp src_file dest_path
Component in a computer that interprets instructions and processes data
cpu
The "brains" of the computer
cpu
Strings require library #include
<string.h>
Expressions consisting entirely of constant values are called
constant expressions
Control passes to the next iteration
continue
Phase 2 of C
Compile
move to the beginning of the current line. (pico)
control a
Report current cursor position. (pico)
control c
move to the End of the current line. (pico)
control e
Cut selected text (displayed in inverse characters). (pico)
control k
To invoke the spelling checker. (pico)
control t
Returns true when its condition is false
!
Assembler is the program that does this translation
Assembly language
Phase 3 of C
Link
15 decimal places
double , %lf
Strlen ______ includes null.
does not
the most common #include
#include <stdio.h>
limit it to three places
%.3f
Use "__" with printf to print strings
%s
Returns true if both conditions are true
&&
arithmetic operations
+ - * / %
code to run the program
./a.out
What to put around the header of a program
/* */
What indicates a comment
//
Subscripts or elements in an array always starts with
0
How many arguments in printf("Hello World!\n");
1
how many arguments in printf("sum of 50 and 25 is %d\n", sum);
2
how many arguments in printf("sum of %d + %d is %d\n", a, b, sum);
4
Logical expression
<Boolean expr> <logical operator> <Boolean expr>
General Format for declaring arrays:
<data type> <variable> [size];
Relational expression
<expr> <relational operator> <expr>
defines bool, true, & false, to make it easier working with this type
<stdbool.h>
#include for random numbers
<stdlib.h>
The most common way to seed the random number generator is to use the time function, which is in the _______ library file.
<time.h>
assignment operater
=
Remember to use the ______ operator to test for equality.
==
Add, subtract, multiply, divide
Arithmetic operations
Bitwise operations
Arithmetic operations
Comparison
Arithmetic operations
Used to write modern operating systems
C
"Spruces up" C, and provides object-oriented capabilities
C++
Dominant language in industry and academia
C++
Object-oriented design very powerful
C++
Superset of C developed by Bjarne Stroustrup at Bell Labs
C++
Who was considered the "father of the computer" - credited with inventing the first mechanical computer, an astonishingly complex device for the 1800s, which eventually led to more complex designs (such as the Mark I in the 1940s)
Charles Babbage
A payroll program written in a high-level language might contain a single statement such as
Compilers
Convert high-level language to machine language
Compilers
combination of individual statements into a logical unit that regulates the flow of execution in a program or function
Control structures
Number of items is known before loop
Counter-Controlled Repetition
Copy data from a register to memory
Data handling and memory
Copy data from memory to a register
Data handling and memory
Read or write data from/to hardware devices
Data handling and memory
Set a register to a value
Data handling and memory
Global & static variables, i.e. variables that exist throughout the program execution
Data segment
Uncut (paste) last cut text inserting it at the current cursor position. (pico)
control u
________ programs developed to execute high-level language programs directly.
Interpreter
Phase 4 of C
Load
cuts the problem in half each time, but uses the result of both halves:
MERGESORT
move forward a page of text. (pico)
control v
/home/chochri/111/junk.txt
absolute pathname
When the program runs, an __________ for the main method is placed on the stack.
activation record
A string IS an ______
array
An indexed data structure that holds a collection of multiple variables
array
The compiler's translation involves the ______, which produces an assembly language version, and then converts that to object code.
assembler
move backward a page of text. (pico)
control y
copies src_file to the folder specified by dest_path and gives it the name dest_file
cp src_file dest_dir/dest_file
take two operands
binary operations
We can use a ______ variable to determine if any swapping occurred during the "bubble up."
boolean
Measured in bytes, kilobytes, megabytes, etc.
both
C does not check _____ on arrays
bounds
If the else is to match the outer if, use...
braces
To avoid confusion, and possible errors, it is best to use ______ even for single statements.
braces
used when we want the computer to choose between two alternative courses of action
branching
Causes immediate exit from a while, for, do/while or switch structure
break
The switch statement ends with
break statement
Traverse a collection of elements and move from the front to the end
bubble sorting
C library functions are used as
building blocks
if _current working directory_ is /home/chochri
can use 111/junk.txt
if _current working directory_ is /home/chochri/111
can use junk.txt
takes you back to your home directory
cd
takes you back one directory
cd ..
takes you to the directory specified by the path provided
cd dir_path
used to store a single character
char
Smallest addressable unit of the machine that can contain basic character set. It is an integer type.
char , %c
stdin redirection
cmd < input-file
Both stdin and stdout redirection
cmd < input-file > output-file
stdout redirection
cmd > output-file
a number, character, or character string that is given or provided is known as a ......
constant
Types of instructions:
data handling and memory, arithmetic operations, control flow operations
For a while loop to execute properly, the loop control variable must be
declared, initialized, tested
Loop executes a specified number of times, number of repetitions is known
definite repetition
_________ have hierarchical, tree-like structure
directories
syntax for do-while loop
do { statements } while ( condition );
this loop always executes body at least once
do-while statement
same as float but with roughly twice the precision
double
vim, pico, gedit, are .....
editors
If the program compiles and links correctly an __________ is produced
executable image
The computer, under the control of its CPU, _______ the program one instruction at a time.
executes
the CPU ______ instructions from memory and ______ them.
extracts, executes
End-of-file controlled loops uses function _______
feof
Reads in characters from the specified file through '\n' or until specified size is reached
fgets
each directory can contain _____ and __________
files, subdirectories
syntax for a for loop
for (initialization; test; increment) basic block
General form for forward direction of a for loop with an array
for (subscript = 0; subscript < size; subscript++)
General form for reverse direction of a for loop with an array
for (subscript = size-1; subscript >= 0; subscript--)
Are often used to assign values to an array
for loops
has an additional argument as its first argument, and sends output to the file specified by the 1stargument
fprintf()
Takes a null-terminated string from memory and writes it to the specified file
fputs
similar to scanf() but with an additional 1st argument; captures input read in from the file specified by the the 1st argument
fscanf()
C is a _______ language.
high-level
Fortran (1954), COBOL (1959)
high-level language
Single statements can accomplish substantial tasks
high-level language
Only performs an action if the condition is true
if
General form of if:
if (Boolean Expression) { statement1; statement2; }
General form of if-else:
if (expression) { statement1A; statement2A; } else { statement1B; statement2B; }
A different action is performed when condition is true and when condition is false
if-else
"Bubble" the _______ to the end using pairwise comparisons and swapping
largest value
how to use feof in a while loop
while (!feof(stdin))
Most flexible loop, no restrictions
while statement
x is not equal to y
x != y
x is less than y
x < y
x is less than or equal to y
x <= y