Midterm II Flashcards
What are the advantages of the waterfall method
Natural flow
Widely used
Reinforces planning first
Clear milestones
What are the steps in the waterfall method
Gathering resources-design-implementation-testing-maintenance
What are the disadvantages of the waterfall method
Not practical
Difficult to implement change
Designers may not be aware of implementation difficulties
What are the steps of the rapid prototyping method
Gathering preliminary requirements
Fast prototyping
User evaluation of the prototype
Repeat
Advantages of rapid prototyping method
Ensures that product meets clients needs
Easy to implement change
Disadvantages of the rapid prototyping method
May not be able to have adequate user involvement
Cost of prototype development
Why test software?
Produce robust software Maintain reputation Lower cost (easier to fix bugs before release)
What do we test during the testing phase
Whether a program works
Input
Output
Set of conditions
How do we test?
Ask how can we make the program fail
Regular tests
Boundary tests
Error testing
What is white box testing
Use internal knowledge of implementation to guide the selection of test cases
This will achieve maximum code coverage
What is black box testing
Use specification to guide the selection of test cases
To achieve the maximum coverage of cases give in the specs
What is debugging
A methodical process of finding and reducing bugs or defects
What are the steps of debugging
Identify where things go wrong Track program state Current location in program Current value of variables Number of iterations through the loop Find when expected state does not match actual state
What is printf debugging
Use a print statement to print values of variables and program location
Print debugging strategies
Linear -start at the beginning and add printf until the end is reached
Binary -start in middle of program
Disadvantages of printf debugging
Time consuming
Modify recompile rerun
What is gdb
A source level debugger.
Maps the state to source code and alls to view variable values and set breakpoints
What is a breakpoint
Internal pausing place in the program
Allows programmers to print variable values and resume running till next break point
Max value of an int
2^16
Max value of an unsigned int
2^16-1
Float vs double
Float keeps 6 significant digits and double keeps 15
Char storage space
8 bits
getchar()
Reads a character and assigns it to a variable
putchar()
Prints the character in the brackets
What is an implicit conversion
Implicit conversions are type conversions handled by compilers
What are the two cases where implicit conversions take place
When operands in a math operation don’t have the same type they will convert to the more complex type
Int will convert to float will convert to double
Secondly when the type expressed doesn’t match the value assigned
Ex: int=8.34 becomes 8
How to tell compiler to convert types and what is this called
(type) expression
This is called explicit conversion
typedef
Typedef is a keyword to assign alternative names to existing types
typedef typename alternative_name
sizeof()
The sizeof operator is used like this :
sizeof(type)
To find the number of bytes (not bits) required to store that type
What is a scalar type
A scalar type is composed of a single element
What is an aggregate type
An aggregate type is composed of multiple elements like an array
Declare a one dimensional array
type name[size]
Where are arrays stored
In stack data rather than in heap data like Java. This means that arrays must have a defined size before run time and can not be dynamically allocated
What happens when you try to access an out of bounds item in your array in C
C does not require that subscript bounds be checked so the behaviour will be undefined. This makes it harder to debug but ultimately more efficient
Array initializer
When an array is initialized it is assignment values. If it is not initialized it is not assigned values (unlike in Java)
How do you find the size of an array using the sizeof operator
int size = sizeof(array)/sizeof(array[0]);
How do we access an item in a 2D array
int m[row][column];
How is a 2D array stored in memory?
Elements of a 2D array are stored in row major order
How to initialize a 2D array?
Can use a nested initializer or fill it using nested loops
What is a variable length array?
A variable length array is an array whose length is declared as a variable. Ex: int a[len]
This is possible only if a value has been assigned to len before the array is declared. In addition a VLA can be multidimensional but can not have initializers
What is a function
A sequence of statements grouped together and given a name
Why use functions?
Divide program into manageable pieces
Avoid duplicating code
How to declare a function
returntype name(inputtype varname)
What happens when you want to find out what scanf returns? Or printf
Scanf returns the number of values successfully read from input
Printf returns te number of characters printed
Argument vs parameters
An argument is what you actually pass to a function when you’re calling it. A parameter is what’s used in a function definition or declaration.
Argument passed by value
You only pass a copy of the value that has been assigned to a variable so the original variable remains untouched. Except in the case of arrays
What is a call stack
A call stack is a data structure in memory that stores information about active functions of a program
What is a wrapper function
The function that calls the recursive function
What part of memory is used to store external variables
The data part of memory
Layout of single file c program
#include directives #define directives type definitions global variable definitions function prototypes (except main) main other function definitions
What is a pointer
A pointer is a variable that stores a memory address
How to declare a pointer
type *pointername
How to initialize pointer
int i, *p;
p=&i;
What will happen if we perform pointer arithmetic on pointers that do not point to array elements?
This will result in an undefined behaviour
what are local variables and where are they stored?
We know that local variables are variables defined inside the body of a function. When we learned the call stack,
we also learned that their storage is allocated automatically once the stack frame of the function is created, and
deallocated automatically when the stack frame is popped out of the call stack.Local variables also have block scope, which means that they are visible from their point of declaration to the end
of the enclosing function body.
what is an external variable and where is it stored?
Indeed, in C, we can declare variables outside any functions, and these
variables are called external variables or global variablesExternal variables have static storage duration. This means that they have permanent memory storage locations
when the program is executing. Thus they retain their values throughout program execution. Previously we learned
that the memory of a process is composed of four parts. Among these four parts, the data part is used to store
external variables., External variables have file scope. This means that they are visible from the point of declaration to the end of
the enclosing file. In other words, after we declare an external variable somewhere in the program, any function
defined afterwards can access this variable. Actually, we will see later that the external (i.e., global) variables have
global scope; i.e., they are accessible from other files as well. If a global variable is defined with the keyword
static then it is visible only within the file scope. It is still stored in the static memory; i.e., data part of the
memory. Actually, we do not call it global or external variable in this case, but just static variable
how should we layout our C program
#include directives #define directives type definitions global variable definitions function prototypes (except main) main other function definitions
what happens when we add an integer to a pointer
First, we can add an integer to a pointer. If pointer p points to a[i], then p+j points to a[i+j]. In other words,
p+j points to an element that is j positions forward in the same array.
how do we write a string
A C string is a sequence of characters followed by a null character (’\0’). Thus, a null character is used to mark
the end of the string. A null character is a character whose numeric, i.e., ASCII, value is 0. This is why it can be
written using the escape sequence ‘\0’When using strings we frequently need to have in mind the byte required to store the null character at the end.
Thus to store a string literal of n characters, we need n + 1 bytes
how to declare a string using a pointer
char *p = “hello, world\n”;
how to declare a string using an array
char str1[6] = “abc”;
what does char* strcpy(char *s1, const char *s2);
do?
it copies s1 to s2 and returns s2. does not change the s1 object
what does char* strcat(char *s1, const char *s2);
do?
adds s2 to s1 and returns s1
what does int strcmp(const char *s1, const char *s2);
do?
strcmp compares the strings lexicographically
what does size_t strlen(const char *s1); do?
returns the length of the string
what is a header file?
– Files that allow different source files (*.c) to share – Function prototypes – Type definitions – Macro definitions – etc. – Naming convention: *.h
how to include your header files?
include “file_name”
– First search the current directory, if not found then
– directories in which system header files reside
how do we use preprocessor conditional compilation
– Example (bit.h): #ifndef BIT_H #define BIT_H typedef int Bit; #endif – Meaning: – If BIT_H is not defined: – Define BIT_H – Include other code up to: – #endif