100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

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

Rating
-
Sold
-
Pages
101
Uploaded on
21-08-2024
Written in
2024/2025

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













Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
August 21, 2024
Number of pages
101
Written in
2024/2025
Type
Class notes
Professor(s)
Rawad
Contains
All classes

Content preview

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
CA$71.67
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
khadijanoor

Get to know the seller

Seller avatar
khadijanoor University of Toronto
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions