SCC111: weeks 1-5 Flashcards
(24 cards)
what is imperative programming?
a programming paradigm that uses statements that change a program’s state
what is declarative programming?
programs described the desired result without necessarily explaining what steps should be performed.
what is the main difference between imperative and declarative programming?
-imperative describes how a problem should be solved
-declarative declares the problem that needs to be solved
what type of programming paradigm is C?
an imperative paradigm
key features, benefits of C
-compact
-low-level
-fast and efficient code
-code can exploit hardware components efficiently
what is meant when we say C is a compiled language?
-compiler is used to translate syntactically correct source code into an executable (binary) file
how can other people’s code be referenced in your code?
include statements
— eg #include <stdio.h></stdio.h>
list the binary operators and their meanings
-Addition: +
-Subtraction: -
-Division: /
-Multiplication: *
-Remainder (mod): %
-logical shift left/right: «/»
list the unary operators and their meanings
-Increment: ++
-Decrement: –
-Add: +=
-Multiplication: *=
list the logical operators
-less than: <
-greater than: >
-less than/equal to: <=
-greater than/equal to: >=
-not/equal to: !=/==
-not: !
-and: &&
-or: ||
what is the benefit of a do while loop?
changes where the validation for doing the while loop is found. means code in the loop is executed at least once.
how would you leave a loop early?
by using ‘break’
how would you skip to the next iteration of a loop?
by using ‘continue’
what constitutes the scope of a variable?
the portion of code from which it can be referenced/accessed
how is an array declared in C?
- int listOfInts[number_of_values];
or
-int listOfInts[3] = {1,2,3};
or
-int listOfInts[] = {1,2,3,4};
what needs to be considered when devising a test case?
-boundary cases
-invalid cases
-uncertain values
what are some techniques for debugging?
-dry-running
-hypothesis testing (tracking variable values)
-runtime debugging (setting breakpoints, using debugger)
what is the programming technique typically used for indirection?
pointers
what is a pointer?
-a variable that holds the address of something else
-could be the address of a variable, process or object
what is the concept of pass by reference vs pass by value?
-to pass by reference a pointer is passed as a parameter. This means the value at the specified memory address can be modified.
-when passing by value, the variable is passed to a function. When the variable is referenced within the process, a copy of the variable is used.
how would you create an integer pointer x, that points to address of variable y?
int *x = &y;
if x is a pointer to a memory location y, how can we set y to 65 using x?
*x = 65;
what process is done in the line *x = 65; ?
dereferencing