C Codesdope C How To Program 8e
C Codesdope C How To Program 8e
Input Unit - the section that receives information from INPUT DEVICES and places it
at the disposal of other units for processing (keyboards, mouse, touch screen).
Other forms of input include receiving voice commands, scanning images and
barcodes, and reading from secondary storage devices (flash drives, floppy disks,
hard drives, CDs, DVDs, etc.). Newer and more modern forms of input include GPS,
motion detection (Microsoft's Kinect), and orientation information using
accelerometers (used in modern smartphones)
Output Unit - the section that takes information and places it on various output
devices for use outside of the computer such as display screens, paper printing,
audio and media players, virtual reality devices, controller vibrations, etc.
Memory Unit - the section that stores data needed for processing. Volatile
information are commonly stored in primary storages (RAM)
Secondary Storage unit - the section that stores long term data that are not
necessarily actively used. Examples include flash drives, hard drives, etc.
Arithmetic and Logic Unit - the manufactoring section that performs calculations
and decision making mechanisms. In today's systems, this is included in the CPU
Data Hierarchy
0101010110 - Bits, the smallest data item that can assume a valume of 0 or 1. It's
called a bit because its short for binary digit -- a digit that can assume only two
values. 8 bits is equal to 1 byte.
Despacito - Fields, a group of characters or bytes that conveys meaning eg. a name.
Database - a collection of data organized for easy access and manipulation. Common
types of databases are called relational databases where data is stored in simple
tables
BIG DATA
1 kilobyte (KB) 1024 bytes (1024 bytes exactly)
1 megabyte (MB) 1024 kilobytes (1,000,000 bytes)
1 gigabyte (GB) 1024 megabytes (1,000,000,000 bytes)
1 terabyte (TB) 1024 gigabytes (1,000,000,000,000 bytes)
1 petabyte (PB) 1024 terabytes (1,000,000,000,000,000 bytes)
1 exabyte (EB) 1024 petabytes (1,000,000,000,000,000,000 bytes)
1 zettabyte (ZB) 1024 exabytes (1,000,000,000,000,000,000,000 bytes)
Languages
Machine Languages - any machine can only understand the machine language defined by
its hardware design. Most machine languages consists of strings of bits.
Assemblers - Assembly languages are languages where the comman inputs/functions are
translated into simple English-abbreviated instructions; formed the basis of high
level languages. Assemblers are translator programs that convert assembly language
instructions into machine languages so the machine can process it
High Level Languages - imporved assembly languages that contained more and more
functions with lesser and lesser need for input. Multiple tasks can now be done by
typing a single line of code using high level languages. The translator program for
high level languages are usually called compilers
OBJECT TECHNOLOGY
Performing tasks in a program requires a METHOD. The method has PROGRAM STATEMENTS
that define the functions or what the method can do. These methods are usually
hidden --in a sense that when the entire program reveals an output, it doesn't
reveal the lines of codes and statements, it just reveals what we want it to
reveal.
A OBJECT is a program unit that has multiple METHODS that define the nature of the
object and what the object can do. And like a method, it *hides* the lines of codes
and statements. It is asically what we call a desired sub-output (as the desired
output can have multiple objects).
A CLASS is then the blueprint towards making the object/s that we want which
contains the written functions, methods, attributes. The process of "creating the
object/s from the blueprints" is what we call instatiation. An object, therefore,
is an instance (the desired output) of its class.
Compiling- the phase in which C translates the code into machine language
Linking - Links the code with standard/private libraries that define and references
functions and how they work to produce an executable image
Loading - Loads the compiled code and allocates it into memory (RAM)
OPERATING SYSTEMS
--Core computer programs that make using computers convenient. Allows each
application to run safely, efficiently, and concurrently.
Kernel - the software the contains the core components of the operating system
printf
--print function
--f stands for formatted
--every line of inside a block must end with a semi colon
escape sequence
\n Newline. Position the cursor at the beginning of the next line.
\t Horizontal tab. Move the cursor to the next tab stop.
\a Alert. Produces a sound or visible alert without changing the current
cursor position.
\\ Backslash. Insert a backslash character in a string.
\" Double quote. Insert a double-quote character in a string
Variables
--variables must declare their data types before assigning a variable name.
--you can define multiple variables in the same line eg. int integer1, integer2;
--variables can be named starting with an underscore or a letter only. the entirety
of the variable name can consist of letters(uppercase and lowercase), digits,
underscores. the variable name can not be a reserved word ie. names of library
functions, methods, and other important words like main, printf
ARITHMETIC FUNCTIONS IN C
Addition: 3 + 2
Subtraction: 3 - 2
Multiplication: 3 * 2
Division: 3 / 2
Modulus: 3 % 2
INCREMENTING/DECREMENTING VALUES
++ ++a Increment a by 1, then use the new value of
a in the expression in which a resides.
++ a++ Use the current value of a in the expression
in which a resides, then increment a by 1.
-- --b Decrement b by 1, then use the new value
of b in the expression in which b resides.
-- b-- Use the current value of b in the expression
in which b resides, then decrement b by 1.
RELATIONAL FUNCTIONS IN C
Equal: 3 == 2
Not Equal: 3 != 2
Greater Than: 3 > 2
Less Than: 3 < 2
Greater or Equal: 3 >= 2
Less or Equal: 3 <= 2
CONDITIONAL STATEMENTS
if (condition) {
statement;
}
RESERVED WORDS/KEYWORDS:
auto do goto signed unsigned
break double if sizeof void
case else int static volatile
char enum long struct while
const extern register switch
continue float return typedef
default for short union
/////////////////////////////////CHAPTER 3
ALGORITHMS
A procedure for solving a problem in terms of the action to be done in the order in
which these actions are executed is called an algorithm
PSEUDOCODE
Artificial informal language that helps understand program structures and
algorithms
--contains action and decision statements
C CONTROL STRUCTURE
SEQUENTIAL EXECUTION is the nature of programs to be executed in the order in which
they're written
SELECTION STRUCTURE
IF...ELSE statement determines if a condition is true or false and performs an
action depending on the verified condition
SWITCH statement determines varying conditions and performs varying actions
depending on the verified condition
IF-- single selection statement
IF...ELSE--double selection statement
SWITCH--multiple selection statement
Chapter discusses everything you should already know about if...else and if..else
if..else statements and provides examples
TERNARY OPERATOR
Condition ? Action If True : Action if false
---printf(variable>=90? "Bigger than 90" : "Lesser than 90");
EXPLICIT
---| int i;
---| short p;
---| p = (short)i; //the parenthesis including the data type is
called a cast operator
---|
///////////CHAPTER 4
///////////Chapter discusses SWITCH and FOR statements in detail
///////////Chapter discusses practical examples of for statements, makes detailed
notes and explanations on ///////////examples' lines of code like the format
specifiers, ASCII standard, assignment values, and a
///////////flowchart on each sample
SWITCH CASE
--multiple selection statement
--a selection statement that works for each case of variables/expressions assuming
constant integral values and doing a specified action for each case
getchar()
--can store any character in any integer data type variable
EOF
--symbolic integer constant normally having the value of -1
////////CHAPTER 5
FUNCTIONS allow you to modularize a program--to design and perform actions on
programs through seperate sections. Variables initialized within a function
definition are called LOCAL VARIABLES. PARAMETERS within functions allow you to
modify data you pass through the function via ARGUMENTS. Using functions allow you
to divide tasks seperately and perform different actions through different
functions. One perk of using functions is SOFTWARE REUSABILITY as standardized
functions can be used to perform specific actions instead of having a customized
code. ABSTRACTION is the term for making use of C functions' software reusability
ie. as in using printf, scanf multiple times instead of having a customized code
for displaying outputs.
log(7.389056) is 2.0
FORMAT SPECIFIERS
long double %Lf
double %f
float %f
unsigned long long int %llu
long long int %lld
unsigned long int %lu
long int %ld
unsigned int %u
int %d
unsigned short %hu
short %hd
char %c
HEADERS
<assert.h> Contains information for adding diagnostics that aid program
debugging.
<errno.h> Defines macros that are useful for reporting error conditions.
<time.h> Contains function prototypes and types for manipulating the time
and date.
enum
---Turns a set of integer constants into programmer-defined types starting from 0.
---enum setname { identifier1, identifier2, identifier3 };
main {
enum setname variable; //enum setname becomes a declaration to programmer
defined type
//variable can contain values
identifier1,2,3 which represents integer constants 0, 1, 2
}
MORE ON IDENTIFIERS
identifiers are used for variable names, function names etc.
Each identifier in a program has other attributes like storage class, storage
duration, scope, and linkage.
STORAGE CLASS
--determines an identifier's storage duration, scope, and linkage.
--STORAGE CLASS SPECIFIERS include auto, register, extern, and static
STORAGE DURATION
--determines the duration of existence of the identifier in memory
SCOPE
--determines where the identifier can be used, referenced, and called
LINKAGE
--determines if the identifier can be used in the current source file or other
source files
keyword AUTO
--specifiers are usually split into AUTOMATIC STORAGE DURATION and STATIC STORAGE
DURATION
--auto explicitly declares a variable to be in automatic storage duration
--local variables are by default in automatic storage duration
--variables in auto exist when program control is within the programming block and
while the block is active then destroyed when program control exits the block
STATIC STORAGE DURATION
--extern and static
--identifiers that are initialized only once (before program executions) and exist
until program termination
--that doesn't mean these variables can be accessed everywhere throughout the
program
--external identifiers (global variables and functions) and local variables
explicitly declared as static are in static storage duration. external identifiers
are extern by default.
--local variables explicitly declared as static are only known in the function that
they are defined. but the difference is, they still retain their value even if
after the function is exited
SCOPE
--identifier scope includes function scope, file scope, block scope, and function-
prototype scope
--