Podcast
Questions and Answers
What is the primary advantage of using structured data in programming?
What is the primary advantage of using structured data in programming?
Arrays can only store elements of different types.
Arrays can only store elements of different types.
False
What is contiguous storage in the context of arrays?
What is contiguous storage in the context of arrays?
Storage without any gaps
An array is a data structure consisting of an ordered set of elements of common type that are stored ____________________ in memory.
An array is a data structure consisting of an ordered set of elements of common type that are stored ____________________ in memory.
Signup and view all the answers
What is the purpose of using #define or const int to specify the size of an array?
What is the purpose of using #define or const int to specify the size of an array?
Signup and view all the answers
.Arrays can only be used to store numeric data.
.Arrays can only be used to store numeric data.
Signup and view all the answers
What is the simplest data structure in the C language?
What is the simplest data structure in the C language?
Signup and view all the answers
We refer to any element in an array by its ____________________.
We refer to any element in an array by its ____________________.
Signup and view all the answers
Match the following terms with their definitions:
Match the following terms with their definitions:
Signup and view all the answers
What is the purpose of using arrays in programming?
What is the purpose of using arrays in programming?
Signup and view all the answers
What is the purpose of the null terminator in a string?
What is the purpose of the null terminator in a string?
Signup and view all the answers
C compilers introduce code that checks whether an element's index is within the bounds of its array.
C compilers introduce code that checks whether an element's index is within the bounds of its array.
Signup and view all the answers
What is the purpose of parallel arrays?
What is the purpose of parallel arrays?
Signup and view all the answers
The index numbering of an array starts at ______________ and extends to one less than the number of elements in the array.
The index numbering of an array starts at ______________ and extends to one less than the number of elements in the array.
Signup and view all the answers
Match the following array concepts with their descriptions:
Match the following array concepts with their descriptions:
Signup and view all the answers
What happens if we specify fewer initial values than the size of an array?
What happens if we specify fewer initial values than the size of an array?
Signup and view all the answers
We can specify the size of an array when we initialize it.
We can specify the size of an array when we initialize it.
Signup and view all the answers
What is the purpose of the '%s' conversion specifier in formatting a string?
What is the purpose of the '%s' conversion specifier in formatting a string?
Signup and view all the answers
The number of memory locations occupied by a string is ______________ more than the number of meaningful characters in the string.
The number of memory locations occupied by a string is ______________ more than the number of meaningful characters in the string.
Signup and view all the answers
What is the value of the null terminator in a string?
What is the value of the null terminator in a string?
Signup and view all the answers
What is the primary goal of using a consistent coding style in programming?
What is the primary goal of using a consistent coding style in programming?
Signup and view all the answers
Using long identifiers in a program makes it easier to read.
Using long identifiers in a program makes it easier to read.
Signup and view all the answers
What should identifiers in a program be?
What should identifiers in a program be?
Signup and view all the answers
According to the Allman coding style, the layout and arrangement of code affects its ______________.
According to the Allman coding style, the layout and arrangement of code affects its ______________.
Signup and view all the answers
Match the following parts of speech with their roles in identifiers:
Match the following parts of speech with their roles in identifiers:
Signup and view all the answers
Notations like Hungarian notation are useful in incorporating the type into the identifier.
Notations like Hungarian notation are useful in incorporating the type into the identifier.
Signup and view all the answers
Why should we avoid using long identifiers in a program?
Why should we avoid using long identifiers in a program?
Signup and view all the answers
A well-written program appears to have been written by ______________ programmer.
A well-written program appears to have been written by ______________ programmer.
Signup and view all the answers
What is the benefit of using a consistent coding style in a program?
What is the benefit of using a consistent coding style in a program?
Signup and view all the answers
Comments should be used to explain the meaning of identifiers in a program.
Comments should be used to explain the meaning of identifiers in a program.
Signup and view all the answers
What is the purpose of using indentation in programming?
What is the purpose of using indentation in programming?
Signup and view all the answers
The recommended indent in C programs is a tab of 2 characters.
The recommended indent in C programs is a tab of 2 characters.
Signup and view all the answers
What is the practical limit on line length, including indentation?
What is the practical limit on line length, including indentation?
Signup and view all the answers
The style of bracing used in these notes is that proposed by _______________________.
The style of bracing used in these notes is that proposed by _______________________.
Signup and view all the answers
Match the following terms with their definitions:
Match the following terms with their definitions:
Signup and view all the answers
Why do we avoid using magic numbers in program code?
Why do we avoid using magic numbers in program code?
Signup and view all the answers
We add trailing spaces at the end of a line.
We add trailing spaces at the end of a line.
Signup and view all the answers
What is the purpose of comments in programming?
What is the purpose of comments in programming?
Signup and view all the answers
We use a single space after _______________________ and around most operators.
We use a single space after _______________________ and around most operators.
Signup and view all the answers
We can specify the size of an array when we declare it, but not when we initialize it.
We can specify the size of an array when we declare it, but not when we initialize it.
Signup and view all the answers
What is the primary advantage of black box testing?
What is the primary advantage of black box testing?
Signup and view all the answers
White box testing is data-driven.
White box testing is data-driven.
Signup and view all the answers
What is an equivalence class in black box testing?
What is an equivalence class in black box testing?
Signup and view all the answers
A flow graph models the ____________________ in the source code.
A flow graph models the ____________________ in the source code.
Signup and view all the answers
Match the following debugging techniques with their descriptions:
Match the following debugging techniques with their descriptions:
Signup and view all the answers
What do you do to trace through the execution of a program using the built-in debugger in Visual Studio?
What do you do to trace through the execution of a program using the built-in debugger in Visual Studio?
Signup and view all the answers
The GNU debugger (gdb) is a graphical debugging tool.
The GNU debugger (gdb) is a graphical debugging tool.
Signup and view all the answers
What do you enter to get online help with a particular command while debugging using gdb?
What do you enter to get online help with a particular command while debugging using gdb?
Signup and view all the answers
A walkthrough solution consists of two parts: the ____________________ of changes and the control flow.
A walkthrough solution consists of two parts: the ____________________ of changes and the control flow.
Signup and view all the answers
What do you do if your program crashes and produces a core dump?
What do you do if your program crashes and produces a core dump?
Signup and view all the answers
What is the primary purpose of testing in software development?
What is the primary purpose of testing in software development?
Signup and view all the answers
Semantic errors can be identified by compilers.
Semantic errors can be identified by compilers.
Signup and view all the answers
What are the two kinds of errors that can occur in programming?
What are the two kinds of errors that can occur in programming?
Signup and view all the answers
Debugging involves locating those ______________ that produce incorrect results.
Debugging involves locating those ______________ that produce incorrect results.
Signup and view all the answers
What is the purpose of walkthroughs and code analysis?
What is the purpose of walkthroughs and code analysis?
Signup and view all the answers
Testing ensures that a program executes successfully for all possible values.
Testing ensures that a program executes successfully for all possible values.
Signup and view all the answers
Why is testing important in software development?
Why is testing important in software development?
Signup and view all the answers
The traditional walkthrough technique simulates instruction-by-instruction ______________ of the CPU and its updating of program data in primary memory.
The traditional walkthrough technique simulates instruction-by-instruction ______________ of the CPU and its updating of program data in primary memory.
Signup and view all the answers
Match the following errors with their definitions:
Match the following errors with their definitions:
Signup and view all the answers
Testing and debugging are separate activities in software development.
Testing and debugging are separate activities in software development.
Signup and view all the answers
What happens when the operating system loads a program into RAM?
What happens when the operating system loads a program into RAM?
Signup and view all the answers
The instructions part of the table is mandatory in a walkthrough table.
The instructions part of the table is mandatory in a walkthrough table.
Signup and view all the answers
What is the purpose of the walkthrough table?
What is the purpose of the walkthrough table?
Signup and view all the answers
The operating system transfers control to the program's ___________________ instruction.
The operating system transfers control to the program's ___________________ instruction.
Signup and view all the answers
Match the following parts of a walkthrough table with their descriptions:
Match the following parts of a walkthrough table with their descriptions:
Signup and view all the answers
What is the purpose of the identifiers in a walkthrough table?
What is the purpose of the identifiers in a walkthrough table?
Signup and view all the answers
The actual addresses in a walkthrough table matter.
The actual addresses in a walkthrough table matter.
Signup and view all the answers
What is the purpose of listing the types in a walkthrough table?
What is the purpose of listing the types in a walkthrough table?
Signup and view all the answers
A walkthrough table is a simplified representation of _______________________ throughout the program's lifetime.
A walkthrough table is a simplified representation of _______________________ throughout the program's lifetime.
Signup and view all the answers
What is the purpose of the walkthrough table?
What is the purpose of the walkthrough table?
Signup and view all the answers
Study Notes
Arrays
- A data structure consisting of an ordered set of elements of common type, stored contiguously in memory.
- The simplest data structure in the C language.
- An array definition takes the form:
type identifier [size];
Elements
- Each element has a unique index, starting from 0, and holds a single value.
- To refer to a specific element, use the array name followed by bracket notation around the element's index.
- Example:
grade[0]
to access the first element of thegrade
array.
Check Array Bounds
- C compilers do not check whether an element's index is within the bounds of its array.
- It is the programmer's responsibility to ensure that the code does not include index values that point to elements outside the memory allocated for an array.
Initialization
- An array can be initialized when it is defined, similar to initializing variables.
- Initialization takes the form:
type identifier [size] = {values};
- Example:
int grade[8] = {90, 80, 70, 60, 50, 40, 30, 20};
- If the initialization fills all elements in the array, the size of the array can be inferred from the initialization set, and it does not need to be specified.
Parallel Arrays
- A convenient way to store tabular information using two parallel arrays.
- One array holds the key, while the other holds values.
- The arrays are parallel because the elements at the same index hold data that are related to the same entity.
Character Strings
- A character string is a char array with a special property: a terminator element follows the last meaningful character in the string.
- The null terminator is identified by the escape sequence '\0' and has the value 0 on any host platform.
- The null terminator occupies the first position in the ASCII and EBCDIC collating sequences.
- The value of the index identifying the null terminator element is the number of meaningful characters in the string.
Coding Style
- A well-written program is easy to read and maintain, with a consistent coding style throughout.
- The Allman coding style is recommended for introductory programming courses.
Identifiers
- Identifiers should be self-descriptive, making it easy for the reader to understand their meaning.
- Avoid referring the reader to external documents for explanation, and instead embed the meaning in the name.
- Short names are easier to read, but avoid very short names that are unclear.
- Nouns describe objects, and verbs describe actions.
- Avoid notations like Hungarian notation that include the type in the identifier.
Layout
- Layout and arrangement affect comfort and accessibility in code.
- Poorly laid out code can frustrate and lead to misreading.
- Negative space can visually separate elements and draw attention to certain parts of the code.
Indentation
- Indentation helps define code block structures and clearly shows logic.
- Recommended indentation is a tab of 4 or 8 characters.
- Using tabs rather than spaces enables easy adjustment of indentation.
- Aligning subordinate case labels with the switch keyword can minimize indentation with switch constructs.
Line Length
- The practical limit on line length is 80 columns, including indentation.
- Lines longer than 80 columns can be difficult to read, and may truncate or wrap in hard copy printouts.
- Break long string literals into sub-string literals separated by whitespace.
Braces
- The Allman style places the opening brace on its own line, indented to the preceding statement, and the closing brace on its own line, aligned with the opening brace.
- Braces are unnecessary with single statements, but provide clarity and maintainability.
Spaces
- Add a single space after commas, semi-colons, keywords, and around operators, except between parentheses and identifiers or constants.
- Avoid trailing spaces at the end of a line, and use blank lines to distinguish between constructs.
- Use comments to describe what is done, rather than how it is done, and keep them brief.
Comments
- Comments should introduce or summarize what follows, and avoid decoration or cuteness.
- Identify units where they matter, and comment data at the variable's declaration.
- Preface every source file with a header comment that includes the file name, author, date, and description.
Magic Numbers
- Avoid magic numbers by identifying them with symbolic names and using those names throughout the code.
- Set their value in either of two ways: directly in the code or through a header file.
Unmodifiable Variables
- An unmodifiable variable takes the form
const type identifier = value;
. - Use them to define constants, standard rates, or default values.
Macro Directive
- A macro directive takes the form
#define SYMBOL value
. - It instructs the C compiler to substitute every occurrence of SYMBOL with value throughout the code.
- Terminate the directive with an end of line character immediately following the value.
Introduction to Testing and Debugging
- Testing and debugging are essential skills for software developers to refine throughout their career.
- Testing ensures that a program executes successfully for a well-defined range of values, but may still crash for values outside this range.
- Debugging locates errors that produce incorrect results.
Errors
- Errors are classified into two kinds: syntactic and semantic errors.
- Syntactic errors break the rules of the programming language.
- Semantic errors fail to implement the intent and meaning of the program designer.
Testing Techniques
Black Box Testing
- Black box testing is a data-driven technique that treats the program as a black box.
- It tests the program against specifications and is input-output driven.
- Equivalence classes are used to reduce the number of possibilities to be tested.
White Box Testing
- White box testing is a logic-driven technique that treats the program as a glass box.
- It tests each possible path through the code at least once.
- Flow graphs are used to model the sequences, selections, and iterations in the source code.
Debugging Techniques
IDE Debugging
- Integrated Development Environments (IDEs) support text editing, coding, compiling, testing, and debugging in a unified application.
- The IDE used in this course is Microsoft's Visual Studio.
- Build and execute C programs in Visual Studio by creating a new project, writing the code, and clicking the "Local Windows Debugger" button.
Command-Line Debugging
- The GNU debugger (gdb) is a command-line debugging tool that ships with the gcc compiler for Linux platforms.
- Compile the source code with the -g option to use gdb.
- Run gdb by entering
gdb a.out
and set breakpoints before running the program.
Walkthrough Table
- A walkthrough emulates the CPU stepping through the code and is used to understand the control flow and memory changes of a source code snippet.
- The walkthrough solution consists of a record of changes and a table of program variables.
- The table lists the identifiers, types, and values of the variables, and is a simplified representation of RAM throughout the program's lifetime.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers the use of arrays in programming, including their efficiency and organization in processing large amounts of data. Learn how arrays can improve data processing speed and how they are stored in memory.