100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Introduction to computer science 2 (csca48) notes + exercises + midterm $50.49   Add to cart

Class notes

Introduction to computer science 2 (csca48) notes + exercises + midterm

 27 views  0 purchase
  • Course
  • Institution

All notes from reading sections, lectures All exercises done Memory models examples Midterm reviews with answers Final exam review with answers All details

Preview 5 out of 101  pages

  • August 21, 2024
  • 101
  • 2024/2025
  • Class notes
  • Rawad
  • All classes
avatar-seller
CSCA48"




duf

, Unit #1 -
Intro.doesn't have
interactive mode
needs compile :
for Syntax
code- code (also checks
~

empileid
/
: source


does something

human understandable P
-T imperative
I : step by Step-how program
High level understanding
:
simple : more focus on

[ EY
-




Low level
: machine
ciese language -

how computer works
-
need to know details
return o; successful running & # include stdio h
include and use code from
.




Libraries :
program can
23
Delimiters : code that belongs to a specific scope
'a' or
:

Comments in Al 11 e'$' or
in ar , void
:
or

Fundamental data types ,
floats double ,
: int

Variables are local t that function -




·
In : new line
Collection
GCC :
GNU compiler

file . - file- new
Specify Name :
gcc

quotes only
"
Use double
Errors
( missing ;I
Common :


of "I "

before return Is I instead
.




-

expected';" for itstype
constant too long
before string constant
char
-warning :
or ...
-

expected declaration specifers
I printf a fer ? %ht 3 . 145)
fr variables
,
:
p pointer
Format specifiers %C Char is string => 5 . 15

%f float
decimal 2 %at 5 1)
Yd sci notation
.

,
num using 14
floating point
= 3 .




% g
Control Sequences % print of
Common 1) print
It tab
In new line
while
il;3 for loop
updates printf("Yd"
Y
,

i readability
:
· Loops condition
for Lintialization ;
2) less code , less
For loops bugs
while loops
·
conditional Statements
if and else
( = , , >, =, =, !
operators
=


Comparison
·
88 !
Common
· logical Operators (11 ,




E
specify
decimal to 2 Check square approach
%. If :

one loop

func
-




·

Running : -iss
guare
x-wall-sta 199-file -oname .
- nested loop
= .




g break ;
-

while loop

on
laptop

,Un -
Model Runs

squarell gets
in
AM
erased

TerTeddy
Note :
<int square()
int square (intx]3 main -2)
.




Fi
m
-
= I

⑮put Geturr E




↑·
E
int si put -


S =


return s;
X D
xi
E into Lint
(local var)



int main()S
int input ; Global
int output;
in put = 7 ;

output =
square(inputt ; 3
the value for arguments
-
pass
by value making : a
copy of input
- -


Scope where variable can be referenced and manipulated
local variable scope
:


(input para and
-




variable between curly brackets
Local variable :



(difficult to debug
-




Global variable : can be used by all functions .




·
-




E [
int Xa 114 in y
=
113 - Note :


int square (15 25 3/n
-




Passing array
or pointer
X= X * X; 3 [int >
don't
main()E < global >
to function , you
a
int
are fixed .
need to reassign them
59 Data types
1 =




square) ; 3



as they are references
.

~
O X 2
.



g
-
reverse (array)
-




Type casting "
I 5/2 reversecarray X
=
result array =
int y: X ,
=
2 asint (x , y)
float result : 5
0 as float
result
enough) to get :So
=
2
Gresult
.



is
X/y ; =

[int] Lints <float > cast float() Cone
X = 5 % you can type
y
=
29
int
210] ;
-read and store values array
IOD
Array e
g
.
:
-




- non-extendable T


O to 1
n
type
-



same
-




-
all entries must have
NO WARNING for outside indexing
=
-




string
: char sing[1020]
tri :
end oftring deliminator
-




string [O] 'It's :
strings are properly terminated
compiler adds it to ensure
string [1] 10:
=


OR USE



J
# include <string he (variable "Store this") ;
eg strcpy
.




string
,


intialize a
Strcpyc
· :

strcat(variable, "also this") ;
result :



str cat)) concatenate strings e g alsothis
.
.


:
·
printf("s" variable); > store this
,


· strlen() : len of a string egstulen (var) ;
equal stremp (varl varz) ;
strings and returns if e.g ,
·
strempC :
compares 2 o
if var1 < var2 then - -

- Pointer : variable that contains memory address
.
if var 1 .
) var 2 then - +
= = var2
-
> 0
address of if vari
-
S :
get memory
intialize pointera contents of
-intap; dereference a pointer dereference
and change
&:

address (1)
then
- * (-- p) = 12 ; change memory
value
-
var =
Ap ; var stores p's

, Unit #2

declare
van is 18
My int
-address of int s
1 15
de referencing My
int is 21
My




1
m
Note :




Imp things to remember
① Always NULL
set pointer =



NULL
Check
② if pointer is
will crash
or
program
data from
Make sure accessing

Q ⑤ P index
.
pointers is within
# Arrays are passed as pointers
.
↑3 I %
NOLL


int > int >
L Listin




Set second of to 10
entry array

Main

(p + 1) = 10 %


prese
o
g
_




-
-
compiler



Exercises
.

Ex 1 Reverse string #define MAX 1027 int main()




I
word [MAX] ;
void reverse (char word(s) char

Stropy (word , "Joe") ;
int length strenword
=




(word) ; them
for (inti = 0 ; i < length/2 ; it s reverse / for arrays you don't reassign
11 word reverse (word) ; is wrong
.
char temp word[i] ;
e
g
.


=




word[i] =
word length-i-I ;
word[length 1-i] = temp
;
-




Ex Takes array , query target chars and replaces query
, w
targetchar
void replace (char word [] , char query , char targets

intlenstenworda
if(word (i) ==
query)3
word[i] =
targets
3

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller khadijanoor. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $50.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76449 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$50.49
  • (0)
  Add to cart