Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
126 views

C Codesdope C How To Program 8e

The document discusses core components of computers including input, output, memory, arithmetic logic, and central processing units. It then covers data hierarchy from bits to files and databases. Big data sizes and computer languages from machine to high-level are also summarized.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views

C Codesdope C How To Program 8e

The document discusses core components of computers including input, output, memory, arithmetic logic, and central processing units. It then covers data hierarchy from bits to files and databases. Big data sizes and computer languages from machine to high-level are also summarized.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Software - the instructions that you write to command computers to perform actions

and make decisions


Hardware - the physical components; the computers

Logical Units (Core Components of Computers):

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

Central Processing Unit - the brain section/administrative section that coordinates


and supervises all operations of other logical units/components. Today's systems
have multiple core processors that can handle more processing power and perform
faster and better.

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.

ABCabc@&( - Characters, a set that includes letters, symbols, decimals used to


write computer programs and represent data -- as computers can only process 0s and
1s. A single character is composed of bits that correspond to a pattern of 0s and
1s that can reach up to one, two, or even four bytes. These character sets are
standardized by multiple companies/organizations like Unicode and ASCII.

Despacito - Fields, a group of characters or bytes that conveys meaning eg. a name.

Luis Fonsi Despacito - Records, a group of relevant fields.

Luis Fonsi Despacito


Luis Fonsi Despacito 2
Despacito3 Luis Fonsi
-Files, a group of related records. In some systems, files are considered to be
simply a sequence of bytes.

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.

Instance variables dictate a class' attributes

C Program Development Phases


Editor - Consists of editing a software using the c programming language. Text
editors such as sublime text, emacs, and vim are used

Preprocessing - A preprocessor program executes before the start of a program's


compiling. These programs obey special commands called preprocessor directives that
indicate certain manipulations before compiling.

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)

Execution - Runs the code for the desired output

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

THE C PROGRAMMING LANGUAGE


#include
--a preprocessor directive telling the program to INCLUDE the <stdio.h> Standard
Input/Output Header that includes basic library functions like printf

int main (void)


--the main function. every c program must have a main function and as the main
function is declared as INT, it can return an integer value. but as main is
attributed with VOID, it doesn't return any value

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

char 1 byte -128 to 127 or 0 to 255


unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or
-2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 8 bytes -9223372036854775808 to
9223372036854775807
unsigned long 8 bytes 0 to 18446744073709551615
scanf("%d", &intvariabalename);
--%d is a format control string that indicates the type of format to be inputted
--% is considered by the scanf to be the start of a conversion specifier while d
stands for decimal integer
--ampersand & is called the address operator that addresses the variable
--this entire line of code is interpreted as scanf asking for an integer type input
from the user and then assigning that input to intvariablename

prinf("my favorite number is %d\n", favnum);


--format controls are necessary when wanting to print a specified assigned variable
--you can also have a format control with calculations between variables or
constants

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 OPERATOR IN C (?:)

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

TRANSFER OF CONTROL is the ability of programs to specify which statements to be


executed other than the normal sequential execution

SEQUENCE STRUCTURE is the structure of the program's execution order

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");

ITERATION STRUCTURE (LOOPS)


WHILE loop allows you to specify an action to be repeated until it satisfies a
condition
DO...WHILE allows you to specifiy an action to be repeated until it satisfies a
condition but executes the action before checking the condition
---do {
statements
} while(condition);
FOR... iteration is mainly used for counter controlled iteration
---for (initialization of control variable; condition; increment){
statement
}
/////////////Chapter discusses while loop only and provides examples of which you
should already know and understand
/////////////Chapter discusses pseudocode/algorithm standards, revisions, and
conventions that are self-explanatory
/////////////Chapter discusses flowchart basics and samples
/////////////Chapter will discuss more things that need to be noted but at this
point im done with chapter 3
/////////////revisit chapter next day

COUNTER CONTROLLED ITERATION


--a type of looping where the number of times a statement in an iteration structure
should executed is stated
---needs a control variable initialized to know the number of iteration
SENTINEL CONTROLLED ITERATION/INDEFINITE ITERATION
--the number of times a loop executes isnt stated and the loop executes until such
time where the stated condition is satisfied

DATA TYPE CASTING AND CAST OPERATORS


--changing the data type of a variable explicitly or implicitly
IMPLICIT
---| int i;
---| float j;
---| j = i;
---|
---|OUTPUT
---|//variable i becomes a float

EXPLICIT
---| int i;
---| short p;
---| p = (short)i; //the parenthesis including the data type is
called a cast operator
---|

FORMAT SPECIFIERS/FORMAT CONTROL/CONVERSION SPECIFIER


--% as discussed is the start of a conversion specifier
--%.2f is regarded as converting the format into a float with 2 decimal places, .2
is called the PRECISION indicating the precision of the value
////////////////Chapter discusses the nature of format specifiers lightly, all
types of format specifiers
////////////////can be seen online
////////////////After rereading, chapter discusses assignment operators (with focus
on decrementing and ////////////////incrementing operators) and secure c
programming (efficient memory allocation of coding)
////////////////Chapter discusses lightly on uncommon data types like |unsigned
int| which is basically an
////////////////integer without negatives
////////////////Chapter discusses lightly c11 standards and introduces new
functions that I think are not ////////////////necessary for now

///////////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

|switch(variable that could assume multiple constant integral values){


| case "integral value equivalent":
| statements;
|
| case "multiple cases":
| case "could have one action":
| statement;
|}

getchar()
--can store any character in any integer data type variable

EOF
--symbolic integer constant normally having the value of -1

BREAK AND CONTINUE STATEMENTS


BREAK statement is a command used in iteration sequences for immediate exits from
the loop. used commonly as an action after certain condition within a loop has been
specified.

CONTINUE statement is a command used in iteration sequences for skipping a a


specified statement (commonly after a certain condition within a loop has been
specified) and continuing the next iteration of the loop

///////////Chapter discusses in depth logical operators and provides examples,


focuses once more on assignment operators and distinction from logical equality
///////////Chapter end but will reread for more focus

////////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.

function declaration and function definition


|//Declaration
|return_type/*(type of data the function returns)*/ function_name(declared
parameters, declaredparameters);
|
|void main(){
| codes;
| function_name(arguments, arguments); //function call
|}
|//Definition
|return_type(type of data the function returns) function_name(declared parameters,
declaredparameters){
| codes;
| statements; //function
body
|}

you can also define functions at the time of declaration


If a function doesn't return any value, you can attribute the return type with void
MATHEMATICAL FUNCTIONS
sqrt(x) square root of x sqrt(900.0) is 30.0
sqrt(9.0) is
3.0

cbrt(x) cube root of x (C99 and C11 only) cbrt(27.0) is 3.0


cbrt(-8.0)
is -2.0

exp(x) exponential function e^x exp(1.0) is 2.718282


exp(2.0) is
7.389056

log(x) natural logarithm of x (base e) log(2.718282) is 1.0

log(7.389056) is 2.0

log10(x) logarithm of x (base 10) log10(1.0) is 0.0


log10(10.0)
is 1.0
log10(100.0)
is 2.0

fabs(x) absolute value of x as a floating-point number


fabs(13.5)
is 13.5
fabs(0.0) is
0.0
fabs(-13.5)
is 13.5

ceil(x) rounds x to the smallest integer not less than x


ceil(9.2) is
10.0
ceil(-9.8)
is -9.0

floor(x) rounds x to the largest integer not greater than x


floor(9.2)
is 9.0
floor(-9.8)
is -10.0

pow(x, y) x raised to power y (x^y) pow(2, 7) is 128.0


pow(9, .5)
is 3.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

Last In/First Out (LIFO) Data Structure


Function Call Stack
When a function is called, it creates a stack frame containing local variables
within that function and the return location of where that function should return
values. When a function is called and that function, as it is defined, calls
another function, the stack frame pushes the latter function's local variables and
return location is stacked over the former function and is the first to return
value and have its local variables popped off.
---di mo to maiintindihan pag wala kang illustration

HEADERS
<assert.h> Contains information for adding diagnostics that aid program
debugging.

<ctype.h> Contains function prototypes for functions that test characters


for certain
properties, and function prototypes for functions that can
be used to convert
lowercase letters to uppercase letters and vice versa.

<errno.h> Defines macros that are useful for reporting error conditions.

<float.h> Contains the floating-point size limits of the system.

<limits.h> Contains the integral size limits of the system.

<locale.h> Contains function prototypes and other information that enables a


program to
be modified for the current locale on which it’s running.
The notion of locale
enables the computer system to handle different conventions
for expressing data
such as dates, times, currency amounts and large numbers
throughout the world.

<math.h> Contains function prototypes for math library functions.

<setjmp.h> Contains function prototypes for functions that allow bypassing


of the usual
function call and return sequence.

<signal.h> Contains function prototypes and macros to handle various


conditions that
may arise during program execution.

<stdarg.h> Defines macros for dealing with a list of arguments to a function


whose number and types are unknown.

<stddef.h> Contains common type definitions used by C for performing


calculations.

<stdio.h> Contains function prototypes for the standard input/output


library functions,
and information used by them.

<stdlib.h> Contains function prototypes for conversions of numbers to text


and text to
numbers, memory allocation, random numbers and other
utility functions.

<string.h> Contains function prototypes for string-processing functions.

<time.h> Contains function prototypes and types for manipulating the time
and date.

RNG Sample Function


Involves stdlib.h
---rand() is a function that generates integers from 0 to RAND_MAX (an stdli
bconstant detailing the maximum value rand() can generate) which is at
least equal to 32767, the maximum value of a 16bit integer. rand() doesn't
necessarily generate randomly, it generates randomly once and outputs the same
numbers for each execution. to produce truly random numbers every
execution you must seed rand() with srand(a), where a is any integer that should be
different for each execution
---srand(time(NULL)) is srand without having the need to pass in an argument each
time

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
--

You might also like