quiz image

Quiz 5 IPC

VibrantSwamp avatar
VibrantSwamp
·
·
Download

Start Quiz

Study Flashcards

70 Questions

What is the primary advantage of using structured data in programming?

It processes data more efficiently

Arrays can only store elements of different types.

False

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.

contiguously

What is the purpose of using #define or const int to specify the size of an array?

To facilitate modifiability

.Arrays can only be used to store numeric data.

False

What is the simplest data structure in the C language?

An array

We refer to any element in an array by its ____________________.

index

Match the following terms with their definitions:

Array = A data structure consisting of an ordered set of elements of common type Contiguous storage = Storage without any gaps Element = A single variable in an array Index = A way to refer to an element in an array

What is the purpose of using arrays in programming?

To process data more efficiently

What is the purpose of the null terminator in a string?

To indicate the end of the string

C compilers introduce code that checks whether an element's index is within the bounds of its array.

False

What is the purpose of parallel arrays?

To store tabular information, where one array holds the key and the other holds values.

The index numbering of an array starts at ______________ and extends to one less than the number of elements in the array.

0

Match the following array concepts with their descriptions:

Index = A unique identifier for each element Bracket notation = Used to refer to a specific element in an array Initialization = The process of assigning values to an array when it is defined Parallel arrays = Arrays that hold related data, where one array holds the key and the other holds values

What happens if we specify fewer initial values than the size of an array?

The remaining elements are initialized with zero values

We can specify the size of an array when we initialize it.

False

What is the purpose of the '%s' conversion specifier in formatting a string?

To send the contents of the string to standard output

The number of memory locations occupied by a string is ______________ more than the number of meaningful characters in the string.

one

What is the value of the null terminator in a string?

0

What is the primary goal of using a consistent coding style in programming?

To make the code easier to read and maintain

Using long identifiers in a program makes it easier to read.

False

What should identifiers in a program be?

self-descriptive

According to the Allman coding style, the layout and arrangement of code affects its ______________.

comfort and accessibility

Match the following parts of speech with their roles in identifiers:

Nouns = describe objects Verbs = describe actions Adjectives = describe properties Adverbs = describe actions

Notations like Hungarian notation are useful in incorporating the type into the identifier.

False

Why should we avoid using long identifiers in a program?

because they tire the eyes when searching through code

A well-written program appears to have been written by ______________ programmer.

one

What is the benefit of using a consistent coding style in a program?

It makes the code easier to maintain and update

Comments should be used to explain the meaning of identifiers in a program.

False

What is the purpose of using indentation in programming?

To visually separate code blocks

The recommended indent in C programs is a tab of 2 characters.

False

What is the practical limit on line length, including indentation?

80 columns

The style of bracing used in these notes is that proposed by _______________________.

Eric Allman

Match the following terms with their definitions:

Magic Numbers = Values that appear out of nowhere in program code Unmodifiable Variables = Variables that take the form const type name = value; Macro Directive = A directive that substitutes a value for a symbol throughout the code

Why do we avoid using magic numbers in program code?

They make the code less maintainable

We add trailing spaces at the end of a line.

False

What is the purpose of comments in programming?

To describe what is done, rather than how it is done.

We use a single space after _______________________ and around most operators.

commas, semi-colons, and most keywords

We can specify the size of an array when we declare it, but not when we initialize it.

False

What is the primary advantage of black box testing?

It is data-driven

White box testing is data-driven.

False

What is an equivalence class in black box testing?

A set where any member is as good as any other

A flow graph models the ____________________ in the source code.

sequences, selections and iterations

Match the following debugging techniques with their descriptions:

IDE Debugging = Using Integrated Development Environments (IDEs) for debugging Command-Line Debugging = Using the GNU debugger (gdb) for debugging Tracing = Stepping through the execution of a program statement by statement

What do you do to trace through the execution of a program using the built-in debugger in Visual Studio?

Set breakpoints and then enter the run command.

The GNU debugger (gdb) is a graphical debugging tool.

False

What do you enter to get online help with a particular command while debugging using gdb?

help command

A walkthrough solution consists of two parts: the ____________________ of changes and the control flow.

record

What do you do if your program crashes and produces a core dump?

Enter 'where' and 'bt' commands in gdb.

What is the primary purpose of testing in software development?

To ensure that a program executes correctly for all practical cases

Semantic errors can be identified by compilers.

False

What are the two kinds of errors that can occur in programming?

Syntactic errors and semantic errors

Debugging involves locating those ______________ that produce incorrect results.

bugs

What is the purpose of walkthroughs and code analysis?

To identify semantic errors

Testing ensures that a program executes successfully for all possible values.

False

Why is testing important in software development?

To ensure that a program executes correctly for all practical cases

The traditional walkthrough technique simulates instruction-by-instruction ______________ of the CPU and its updating of program data in primary memory.

stepping

Match the following errors with their definitions:

Syntactic Errors = Errors that break the rules of the programming language Semantic Errors = Errors that fail to implement the intent and meaning of the program designer

Testing and debugging are separate activities in software development.

False

What happens when the operating system loads a program into RAM?

The program instructions occupy one part of memory while the program variables occupy another part

The instructions part of the table is mandatory in a walkthrough table.

False

What is the purpose of the walkthrough table?

To track each change in RAM

The operating system transfers control to the program's ___________________ instruction.

first

Match the following parts of a walkthrough table with their descriptions:

Identifiers = List of variable names Types = Data types of variables Addresses = Memory locations of variables Values = Current values of variables

What is the purpose of the identifiers in a walkthrough table?

To list the variable names

The actual addresses in a walkthrough table matter.

False

What is the purpose of listing the types in a walkthrough table?

To list the data types of variables

A walkthrough table is a simplified representation of _______________________ throughout the program's lifetime.

RAM

What is the purpose of the walkthrough table?

To track changes in the program variables

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 the grade 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.

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.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Arrays in Programming
6 questions

Arrays in Programming

MagicalBlessing avatar
MagicalBlessing
Data Structures: Array-Based Lists
12 questions
        -  4:
30 questions

- 4:

QuickerAltoFlute avatar
QuickerAltoFlute
Use Quizgecko on...
Browser
Browser