1. Home
  2. Explore
  3. Computer Science
  4. C Programming Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

C Programming Fundamentals

  • 101Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: C Tools and Execution

Why can learning C provide a useful foundation for learning other programming languages?

101 questions

  1. 1

    Why can learning C provide a useful foundation for learning other programming languages?

    1. A

      Programs written in other languages must first be compiled in C.

    2. B

      C uses the same syntax as all modern programming languages.

    3. C

      C automatically converts programs into every other language.

    4. D

      Many modern programming languages are based on C.

    Correct answer
    D

    Many modern programming languages are based on C.

    Explanation

    The content notes that many modern programming languages are based on C, so learning C can help build a foundation for learning languages such as C++.

  2. 2

    What is the role of a text editor when programming in C?

    1. A

      It allocates memory for every variable in a running program.

    2. B

      It automatically decides the order in which instructions run.

    3. C

      It lets a programmer write and save program text in a file.

    4. D

      It translates program text into instructions the computer executes.

    Correct answer
    C

    It lets a programmer write and save program text in a file.

    Explanation

    A text editor provides a place to write text and save it in a file. Translating C code into a form the computer can execute is the compiler's role.

  3. 3

    What makes an IDE different from a basic text editor, according to the content?

    1. A

      It is a data type used to store program instructions.

    2. B

      It provides a specialized environment for writing, running, and managing programs.

    3. C

      It removes the need to write program instructions in a source file.

    4. D

      It allows a computer to execute C code without compiling it.

    Correct answer
    B

    It provides a specialized environment for writing, running, and managing programs.

    Explanation

    An IDE, or integrated development environment, is a specialized environment that helps programmers write, run, and manage programs.

  4. 4

    Why does a C program need to be compiled before the computer can execute it?

    1. A

      The C source must be translated into a form the computer can understand.

    2. B

      The compiler replaces the program's instructions with user input.

    3. C

      The source must be divided into separate variables.

    4. D

      The source file must be converted into a text document.

    Correct answer
    A

    The C source must be translated into a form the computer can understand.

    Explanation

    C code is written in a form people can work with. A compiler translates or transforms it into a language the computer can execute.

  5. 5

    What does building or compiling a C program do, as distinct from running it?

    1. A

      It saves the program's variables to a file.

    2. B

      It translates the C source into code the computer can execute.

    3. C

      It displays all program output in the console.

    4. D

      It tells the computer to execute the translated code.

    Correct answer
    B

    It translates the C source into code the computer can execute.

    Explanation

    Building or compiling translates C code into code the computer can understand. Running then executes that built code.

  6. 6

    In the described Code::Blocks workflow, what does a build-and-run command do?

    1. A

      It compiles the program and then executes it.

    2. B

      It prints the source code and then saves the output.

    3. C

      It runs the source code first and compiles it afterward.

    4. D

      It edits the source file and then creates a project.

    Correct answer
    A

    It compiles the program and then executes it.

    Explanation

    Build and run combines the two steps: it builds or compiles the program and then runs the resulting executable code.

  7. 7

    What is the purpose of the main function in a C program?

    1. A

      It stores every variable declared in the program.

    2. B

      It displays the program's output without requiring instructions.

    3. C

      It compiles all other functions when they are defined.

    4. D

      It is the function the program executes when it starts.

    Correct answer
    D

    It is the function the program executes when it starts.

    Explanation

    When a C program runs, execution begins in main; the instructions inside its braces are carried out.

  8. 8

    What does a printf instruction do when execution reaches it?

    1. A

      It prints specified information to the screen.

    2. B

      It translates source code into machine instructions.

    3. C

      It repeats the preceding instruction.

    4. D

      It reads a line of text from a file.

    Correct answer
    A

    It prints specified information to the screen.

    Explanation

    printf is used to print text or other specified information to the screen.

  9. 9

    What is a variable in C?

    1. A

      A named container used to store information in a program.

    2. B

      A command that translates a program into machine code.

    3. C

      A function that displays information on the screen.

    4. D

      A condition that determines whether a loop repeats.

    Correct answer
    A

    A named container used to store information in a program.

    Explanation

    A variable is a container for data values, such as numbers, characters, or text, that a program can use and manage.

  10. 10

    Why can storing a character's name in one variable make a long program easier to maintain?

    1. A

      The name can be changed in one place instead of at every occurrence.

    2. B

      The variable automatically shortens every line that uses the name.

    3. C

      The variable prevents the program from printing the name more than once.

    4. D

      The compiler replaces all other variables with the character's name.

    Correct answer
    A

    The name can be changed in one place instead of at every occurrence.

    Explanation

    When a program refers to a variable wherever the name is needed, changing the stored value once updates all those uses.

  11. 11

    Which declaration is appropriate for storing a whole-number age, such as 353535?

    1. A

      double age = '35';

    2. B

      int age = 35;

    3. C

      char age = 35.0;

    4. D

      int age = "35";

    Correct answer
    B

    int age = 35;

    Explanation

    An int stores an integer, which is a whole number. The content uses an integer variable for a character's age.

  12. 12

    Which declaration uses the data type recommended in the content for a beginner storing a GPA such as 3.73.73.7?

    1. A

      double gpa = "3.7";

    2. B

      char gpa = '3.7';

    3. C

      int gpa = 3.7;

    4. D

      double gpa = 3.7;

    Correct answer
    D

    double gpa = 3.7;

    Explanation

    A double represents a decimal number, and the content recommends using double for decimal values as a beginner.

  13. 13

    What distinguishes the integer value 404040 from the double value 40.040.040.0 in C?

    1. A

      404040 is a double, while 40.040.040.0 is an integer.

    2. B

      404040 is a string, while 40.040.040.0 is a character.

    3. C

      404040 is an integer, while 40.040.040.0 is a decimal-number value.

    4. D

      404040 is a character, while 40.040.040.0 is an integer.

    Correct answer
    C

    404040 is an integer, while 40.040.040.0 is a decimal-number value.

    Explanation

    An integer is a whole number without a decimal point. A number written with a decimal point, such as 40.040.040.0, is treated as a decimal value.

  14. 14

    How many individual characters can a basic char variable store?

    1. A

      One complete line of text.

    2. B

      Any number of characters separated by spaces.

    3. C

      One word of any length.

    4. D

      One character.

    Correct answer
    D

    One character.

    Explanation

    A char stores a single character. A sequence of characters requires a character array, such as a string.

  15. 15

    How is a string represented in the C examples in the content?

    1. A

      As a single char holding multiple letters.

    2. B

      As a character array.

    3. C

      As a special built-in variable type unrelated to arrays.

    4. D

      As a single integer.

    Correct answer
    B

    As a character array.

    Explanation

    The content explains that a string is a collection of characters represented using char and square brackets, making it an array of characters.

  16. 16

    Why specify a size such as 20 in a character array intended to hold user input?

    1. A

      It tells C how many words the user must enter.

    2. B

      It determines how many times the input function will run.

    3. C

      It makes the string automatically expand to any length.

    4. D

      It tells C how much space to allocate for the characters.

    Correct answer
    D

    It tells C how much space to allocate for the characters.

    Explanation

    When the array is not initialized with a string value, its size tells C how many characters it can hold and how much memory to allocate.

  17. 17

    What does assigning a new value to a variable during execution demonstrate?

    1. A

      A variable can be changed only by a user entering input.

    2. B

      A variable's data type changes automatically with every assignment.

    3. C

      A variable becomes a constant after its first assignment.

    4. D

      A variable's stored value can change as a program runs.

    Correct answer
    D

    A variable's stored value can change as a program runs.

    Explanation

    The content demonstrates changing an age variable partway through a story, showing that ordinary variables can receive new values during execution.

  18. 18

    What is a constant in C, as described in the content?

    1. A

      A number that can be modified only inside a function.

    2. B

      A value declared so that the program cannot modify it.

    3. C

      A data type used exclusively for text.

    4. D

      A variable that changes only when the program is compiled.

    Correct answer
    B

    A value declared so that the program cannot modify it.

    Explanation

    A constant is a value that cannot be modified in the program. The const keyword can make a variable constant.

  19. 19

    What happens if code attempts to assign a new value to a variable declared with const?

    1. A

      The attempted modification causes an error.

    2. B

      The assignment is silently ignored and execution always continues.

    3. C

      The constant is automatically converted into an ordinary variable.

    4. D

      The program changes the constant only after it has been printed.

    Correct answer
    A

    The attempted modification causes an error.

    Explanation

    The content demonstrates that modifying a const variable produces an error because constants cannot be changed.

  20. 20

    Why do developers often write constant variable names in uppercase?

    1. A

      C automatically makes uppercase variables impossible to modify.

    2. B

      Uppercase names prevent the compiler from allocating memory.

    3. C

      It is a convention that makes constants easier to recognize.

    4. D

      C requires uppercase names for every constant.

    Correct answer
    C

    It is a convention that makes constants easier to recognize.

    Explanation

    The content describes uppercase names as a common convention for constants, not a language requirement.

  21. 21

    Which format specifier is used in printf to insert a string into text?

    1. A

      %f

    2. B

      %d

    3. C

      %s

    4. D

      %c

    Correct answer
    C

    %s

    Explanation

    %s acts as a placeholder for a string of characters in printf.

  22. 22

    Which printf format specifier is used to print an integer?

    1. A

      %s

    2. B

      %d

    3. C

      %f

    4. D

      %c

    Correct answer
    B

    %d

    Explanation

    The content uses %d to print an integer value.

  23. 23

    Which printf format specifier is used to print a decimal value such as a double?

    1. A

      %f

    2. B

      %c

    3. C

      %d

    4. D

      %s

    Correct answer
    A

    %f

    Explanation

    In the examples, %f is used in printf to display a floating-point or decimal value.

  24. 24

    Which printf format specifier is used to print one character?

    1. A

      %s

    2. B

      %d

    3. C

      %f

    4. D

      %c

    Correct answer
    D

    %c

    Explanation

    %c is used in printf to print a single character.

  25. 25

    In a printf call with several format specifiers, how should the supplied values be arranged?

    1. A

      In alphabetical order by variable name.

    2. B

      In any order, because C matches values to variables by name.

    3. C

      In reverse order from the specifiers in the format string.

    4. D

      In the same order as the corresponding specifiers appear in the format string.

    Correct answer
    D

    In the same order as the corresponding specifiers appear in the format string.

    Explanation

    The content explains that the order of values supplied after the format string must match the order of the format specifiers.

  26. 26

    What does the escape sequence \n do when included in text printed by printf?

    1. A

      It terminates the program immediately.

    2. B

      It inserts a tab before the next character.

    3. C

      It prints the two characters backslash and n literally.

    4. D

      It moves subsequent output to a new line.

    Correct answer
    D

    It moves subsequent output to a new line.

    Explanation

    \n is a newline character that moves subsequent output onto a new line.

  27. 27

    How can a program print a quotation mark as part of a string without ending the string?

    1. A

      Place a semicolon before the quotation mark.

    2. B

      Place a backslash before the quotation mark.

    3. C

      Replace the quotation mark with %s.

    4. D

      Put the quotation mark outside the printf call.

    Correct answer
    B

    Place a backslash before the quotation mark.

    Explanation

    The content shows that escaping a quotation mark with a backslash lets it be printed as a character within the string.

  28. 28

    What is the basic difference between printf and scanf?

    1. A

      printf compiles a program, while scanf executes it.

    2. B

      printf displays information, while scanf accepts input.

    3. C

      printf reads files, while scanf writes files.

    4. D

      printf accepts input, while scanf displays information.

    Correct answer
    B

    printf displays information, while scanf accepts input.

    Explanation

    printf prints information to the screen, whereas scanf lets the user enter information into the program.

  29. 29

    When scanf stores an integer in an existing variable named age, what form is used in the example?

    1. A

      scanf("%d", &age);

    2. B

      scanf("%c", age);

    3. C

      scanf("%s", age);

    4. D

      scanf("%f", &age);

    Correct answer
    A

    scanf("%d", &age);

    Explanation

    The integer input uses %d, and &age supplies the variable's address so scanf can store the input there.

  30. 30

    Which format string does the content use with scanf to read a double?

    1. A

      %d

    2. B

      %s

    3. C

      %lf

    4. D

      %f

    Correct answer
    C

    %lf

    Explanation

    The content distinguishes scanf from printf: it uses %lf to scan a double, while printf uses %f to print one.

  31. 31

    Which form is used in the content to read a single character into grade with scanf?

    1. A

      scanf("%d", &grade);

    2. B

      scanf("%s", grade);

    3. C

      scanf("%f", grade);

    4. D

      scanf(" %c", &grade);

    Correct answer
    D

    scanf(" %c", &grade);

    Explanation

    The example uses %c with a leading space in the format string and &grade to read a character.

  32. 32

    Why does scanf("%s", name) stop reading a name such as John Smith after John?

    1. A

      A space ends the entire program before input is stored.

    2. B

      For a string, %s stops at the first whitespace.

    3. C

      scanf permits only four characters in every string.

    4. D

      The character array automatically deletes text after the first capital letter.

    Correct answer
    B

    For a string, %s stops at the first whitespace.

    Explanation

    The content explains that scanf with %s reads characters only up to the first whitespace.

  33. 33

    Why is the address operator & used with a numeric variable in the described scanf examples?

    1. A

      It increases the number of characters the variable can store.

    2. B

      It gives scanf the variable's address so the function can store input there.

    3. C

      It tells scanf to print the variable before reading input.

    4. D

      It converts a numeric value into a string.

    Correct answer
    B

    It gives scanf the variable's address so the function can store input there.

    Explanation

    The examples pass the variable's address using &, allowing scanf to place the entered value into that variable.

  34. 34

    Why does the described scanf example pass a character array name without &?

    1. A

      The array name already refers to the character array's storage.

    2. B

      Character arrays cannot receive input from a user.

    3. C

      The ampersand is used only for output functions.

    4. D

      Strings are printed rather than stored when read by scanf.

    Correct answer
    A

    The array name already refers to the character array's storage.

    Explanation

    For the string input example, the array name is passed directly; the content contrasts this with numeric and single-character inputs that use &.

  35. 35

    What does fgets offer for reading a line of user text compared with the described %s use of scanf?

    1. A

      It can read a line containing spaces into a character array.

    2. B

      It converts the line directly into an integer.

    3. C

      It prints the line without storing it.

    4. D

      It reads only the first word and discards the rest.

    Correct answer
    A

    It can read a line containing spaces into a character array.

    Explanation

    fgets reads a line of text and can therefore capture multiple words separated by spaces.

  36. 36

    What is the purpose of the size argument in a call such as fgets(name, 20, stdin)?

    1. A

      It determines the number of times the function is called.

    2. B

      It changes the character array into an integer array.

    3. C

      It limits how many characters the input function accepts.

    4. D

      It specifies how many words must appear on the line.

    Correct answer
    C

    It limits how many characters the input function accepts.

    Explanation

    The size argument limits the number of characters read, helping prevent input from exceeding the available buffer.

  37. 37

    In the described fgets call, what does stdin identify?

    1. A

      The file where the program writes its output.

    2. B

      The memory address of the program's main function.

    3. C

      The maximum number of characters in the array.

    4. D

      The standard input source, such as the console.

    Correct answer
    D

    The standard input source, such as the console.

    Explanation

    stdin stands for standard input and identifies the source from which fgets obtains input, such as the console.

  38. 38

    What newline-related behavior should a program account for when using fgets to read user input?

    1. A

      The newline causes fgets to ignore all input after the first word.

    2. B

      The Enter key always removes the first character of the stored line.

    3. C

      fgets converts the newline into a space before storing the line.

    4. D

      The newline created by pressing Enter may be included in the stored line.

    Correct answer
    D

    The newline created by pressing Enter may be included in the stored line.

    Explanation

    The content notes that pressing Enter supplies a newline character, which can be included in the string read by fgets.

  39. 39

    What result does C produce when two integer operands are divided using integer arithmetic, as in 5/45 / 45/4?

    1. A

      The fractional part is discarded, producing the integer 111.

    2. B

      The operation produces the remainder, which is 111.

    3. C

      The operation causes a compilation error.

    4. D

      The result is automatically a double equal to 1.251.251.25.

    Correct answer
    A

    The fractional part is discarded, producing the integer 111.

    Explanation

    When both operands are integers, the result is an integer; in the example, 5/45 / 45/4 produces 111 rather than 1.251.251.25.

  40. 40

    What is the result type of an arithmetic operation involving an integer and a floating-point value, according to the content?

    1. A

      A string of digits.

    2. B

      An integer in every case.

    3. C

      A floating-point value.

    4. D

      A character value.

    Correct answer
    C

    A floating-point value.

    Explanation

    The content explains that an operation between an integer and a floating-point number returns a floating-point number.

  41. 41

    Which operator represents multiplication in the arithmetic examples?

    1. A

      /

    2. B

      %

    3. C

      +

    4. D

      *

    Correct answer
    D

    *

    Explanation

    The examples use an asterisk for multiplication, a forward slash for division, plus for addition, and minus for subtraction.

  42. 42

    What does the C function pow(2, 3) calculate in the described example?

    1. A

      The next integer greater than 222.

    2. B

      222 raised to the third power.

    3. C

      222 multiplied by 333 once.

    4. D

      The square root of 222.

    Correct answer
    B

    222 raised to the third power.

    Explanation

    pow takes a base and an exponent; pow(2, 3) calculates 232^323, which is 888.

  43. 43

    What does the C function sqrt(36) calculate?

    1. A

      The square of 363636.

    2. B

      The square root of 363636.

    3. C

      The ceiling of 363636.

    4. D

      The remainder after dividing 363636 by 222.

    Correct answer
    B

    The square root of 363636.

    Explanation

    sqrt returns the square root of its argument; the example gives 666 for sqrt(36).

  44. 44

    What does ceil(36.3) do in the described examples?

    1. A

      Rounds the value downward to the previous integer.

    2. B

      Rounds the value upward to the next integer.

    3. C

      Removes the integer part and keeps the decimal part.

    4. D

      Returns the square root of the value.

    Correct answer
    B

    Rounds the value upward to the next integer.

    Explanation

    ceil means ceiling and rounds a decimal value upward; the example produces 373737 from a value such as 36.336.336.3.

  45. 45

    What does floor(36.6) do in the described examples?

    1. A

      Rounds the value upward to the higher integer.

    2. B

      Rounds the value downward to the lower integer.

    3. C

      Squares the value and returns a decimal.

    4. D

      Returns the fractional part of the value.

    Correct answer
    B

    Rounds the value downward to the lower integer.

    Explanation

    floor rounds a decimal value down; the example produces 363636 from a value such as 36.636.636.6.

  46. 46

    What is a comment in C?

    1. A

      Text in the source code that C ignores during execution.

    2. B

      A statement that prints a note to the console.

    3. C

      A special variable that stores program output.

    4. D

      A function that temporarily pauses compilation.

    Correct answer
    A

    Text in the source code that C ignores during execution.

    Explanation

    Comments are marked sections of source code that are ignored when the program runs.

  47. 47

    How can a programmer temporarily prevent a line of code from executing without deleting it?

    1. A

      Place a semicolon before the line.

    2. B

      Place the line inside a comment.

    3. C

      Move the line after the program's final brace.

    4. D

      Rename every variable used by the line.

    Correct answer
    B

    Place the line inside a comment.

    Explanation

    Commenting out code causes C to ignore it while leaving it in the source file.

  48. 48

    What is a good practice concerning comments, according to the content?

    1. A

      Use comments only to replace executable instructions.

    2. B

      Use them when they are useful or necessary, rather than scattering them everywhere.

    3. C

      Write a comment after every individual character in the program.

    4. D

      Avoid all comments, even when code needs explanation.

    Correct answer
    B

    Use them when they are useful or necessary, rather than scattering them everywhere.

    Explanation

    The content recommends using comments sparingly, particularly when they are needed to explain code or convey useful notes.

  49. 49

    What does a while loop do?

    1. A

      Defines a block of code that can be called by name.

    2. B

      Repeats a block of code while its condition remains true.

    3. C

      Executes a block exactly once and then tests its condition.

    4. D

      Selects one matching value from a list of cases.

    Correct answer
    B

    Repeats a block of code while its condition remains true.

    Explanation

    A while loop checks its condition and repeatedly executes its body as long as the condition is true.

  50. 50

    When is the condition of a while loop checked?

    1. A

      After the program has exited the loop.

    2. B

      Only after the loop body has executed once.

    3. C

      Only when the program first starts.

    4. D

      Before each execution of the loop body.

    Correct answer
    D

    Before each execution of the loop body.

    Explanation

    A while loop checks its condition before executing the body, including before its first iteration.

  51. 51

    What distinguishes a do-while loop from a while loop?

    1. A

      A do-while loop checks its condition only at program startup.

    2. B

      A do-while loop cannot repeat its body.

    3. C

      A do-while loop can contain only one instruction.

    4. D

      A do-while loop executes its body before checking its condition.

    Correct answer
    D

    A do-while loop executes its body before checking its condition.

    Explanation

    A do-while loop executes its body first, so the body runs at least once before the condition is checked.

  52. 52

    What causes an infinite loop in the described while loop example?

    1. A

      The index starts at a positive value.

    2. B

      The condition is checked before the body runs.

    3. C

      The loop body contains a printf statement.

    4. D

      The condition stays true because the index is never incremented.

    Correct answer
    D

    The condition stays true because the index is never incremented.

    Explanation

    If the index is not updated, it can remain within the loop's condition indefinitely, causing the loop to continue forever.

  53. 53

    What does index++ do in the loop examples?

    1. A

      Decreases the value of index by one.

    2. B

      Sets index to zero.

    3. C

      Prints the value of index.

    4. D

      Increases the value of index by one.

    Correct answer
    D

    Increases the value of index by one.

    Explanation

    index++ is shorthand for increasing the variable's value by one.

  54. 54

    When does an if statement execute the instructions in its body?

    1. A

      Every time the program reaches a semicolon.

    2. B

      Only when a function returns a value.

    3. C

      When its condition evaluates to true.

    4. D

      Whenever its condition evaluates to false.

    Correct answer
    C

    When its condition evaluates to true.

    Explanation

    An if statement executes its body when the condition is true; otherwise, execution moves past that body.

  55. 55

    What role does else play in an if/else structure?

    1. A

      It defines a condition that must be checked before if.

    2. B

      It repeats the preceding if branch until the condition changes.

    3. C

      It returns a value from the function.

    4. D

      It provides a branch to execute when the preceding if condition is false.

    Correct answer
    D

    It provides a branch to execute when the preceding if condition is false.

    Explanation

    The else block runs when the preceding if condition is false.

  56. 56

    What is the purpose of else if in a chain of conditions?

    1. A

      It defines a loop that repeats while a condition is true.

    2. B

      It makes two conditions both true automatically.

    3. C

      It runs all earlier branches again.

    4. D

      It tests another condition if the preceding condition was false.

    Correct answer
    D

    It tests another condition if the preceding condition was false.

    Explanation

    else if provides an additional condition to test when the earlier if or else if condition was false.

  57. 57

    When is the result of a condition joined with && true?

    1. A

      When at least one condition is true.

    2. B

      Whenever the conditions have different values.

    3. C

      Only when both conditions are false.

    4. D

      When both conditions are true.

    Correct answer
    D

    When both conditions are true.

    Explanation

    The logical AND operator && makes the combined condition true only when both component conditions are true.

  58. 58

    When is the result of a condition joined with || true?

    1. A

      Only when both conditions are false.

    2. B

      When at least one of the conditions is true.

    3. C

      When the two conditions have identical values.

    4. D

      Only when both conditions are true.

    Correct answer
    B

    When at least one of the conditions is true.

    Explanation

    The logical OR operator || makes the combined condition true if one or both of its conditions are true.

  59. 59

    Which operator checks whether two values are equal in a condition?

    1. A

      !=

    2. B

      ==

    3. C

      =

    4. D

      >=

    Correct answer
    B

    ==

    Explanation

    == compares two values for equality. A single = assigns a value, while != checks whether values differ.

  60. 60

    What does the operator != test?

    1. A

      Whether one condition and another are both true.

    2. B

      Whether the left value is greater than the right value.

    3. C

      Whether two values are equal.

    4. D

      Whether two values are not equal.

    Correct answer
    D

    Whether two values are not equal.

    Explanation

    != is the inequality comparison operator; it is true when the compared values are not equal.

  61. 61

    What effect does the negation operator ! have when placed before a condition?

    1. A

      It assigns a value to the condition.

    2. B

      It joins the condition with another using AND.

    3. C

      It repeats the condition until it changes.

    4. D

      It reverses the condition's truth value.

    Correct answer
    D

    It reverses the condition's truth value.

    Explanation

    The negation operator reverses a condition: true becomes false, and false becomes true.

  62. 62

    When is a switch statement especially useful, as described in the content?

    1. A

      When comparing one value against several possible cases.

    2. B

      When translating C code into a form the computer can execute.

    3. C

      When storing multiple values of different types in one variable.

    4. D

      When repeating instructions until a condition becomes false.

    Correct answer
    A

    When comparing one value against several possible cases.

    Explanation

    A switch statement conveniently compares one value, such as a grade, with several possible case values.

  63. 63

    What is the purpose of a break at the end of a switch case?

    1. A

      It converts the case value to a character.

    2. B

      It checks whether the next case matches.

    3. C

      It exits the switch instead of continuing into later cases.

    4. D

      It restarts the switch with the next value.

    Correct answer
    C

    It exits the switch instead of continuing into later cases.

    Explanation

    break exits the switch. Without it, execution can continue into the following cases.

  64. 64

    When does the default branch of a switch execute?

    1. A

      Whenever the first case matches the switch value.

    2. B

      When none of the listed cases matches the switch value.

    3. C

      Before the switch evaluates its value.

    4. D

      After every case, whether or not it matches.

    Correct answer
    B

    When none of the listed cases matches the switch value.

    Explanation

    default serves as the fallback branch when no listed case matches.

  65. 65

    What is the main convenience a for loop provides over a while loop in the described counting pattern?

    1. A

      It guarantees that the body executes at least once.

    2. B

      It places initialization, the continuation condition, and the update together.

    3. C

      It eliminates the need for a condition.

    4. D

      It automatically prints each value of the index.

    Correct answer
    B

    It places initialization, the continuation condition, and the update together.

    Explanation

    A for loop groups the indexing variable's initialization, the loop condition, and its update in the loop header.

  66. 66

    In a for loop that counts from 111 through 555, what does the middle expression specify?

    1. A

      The instruction that runs after every iteration.

    2. B

      The value printed when the loop terminates.

    3. C

      The condition that determines whether another iteration runs.

    4. D

      The initial value assigned to the index variable.

    Correct answer
    C

    The condition that determines whether another iteration runs.

    Explanation

    The middle part of a for loop header is its continuation condition, such as i <= 5.

  67. 67

    Why does the content start an array traversal index at 000?

    1. A

      C array indexing begins at 000, so the first element is at index 000.

    2. B

      C counts array elements backward from the last element.

    3. C

      A loop cannot use an index greater than zero.

    4. D

      The first element of every C array is automatically discarded.

    Correct answer
    A

    C array indexing begins at 000, so the first element is at index 000.

    Explanation

    Array indexing in C starts at 000; thus, an array's first element is accessed with index 000.

  68. 68

    What is an array used for?

    1. A

      Comparing one value against multiple conditions.

    2. B

      Combining several functions into a single instruction.

    3. C

      Storing exactly one value that must be a whole number.

    4. D

      Storing multiple related values in one organized data structure.

    Correct answer
    D

    Storing multiple related values in one organized data structure.

    Explanation

    An array stores multiple values, which can be useful when managing a collection such as a list of numbers.

  69. 69

    What must be true of the elements in a basic C array, as described in the content?

    1. A

      They must all have the same data type.

    2. B

      They must all be named individually.

    3. C

      They must all be initialized by user input.

    4. D

      They must all have different data types.

    Correct answer
    A

    They must all have the same data type.

    Explanation

    The content contrasts arrays with structures: elements in an array share a data type, while a structure can group different types.

  70. 70

    How can a programmer access a particular array element?

    1. A

      Use the array name followed by the element's index in square brackets.

    2. B

      Use the array name followed by the element's value in parentheses.

    3. C

      Use the data type followed by the element's name in braces.

    4. D

      Use the array name followed by a format specifier.

    Correct answer
    A

    Use the array name followed by the element's index in square brackets.

    Explanation

    The examples access elements using the array name and an index enclosed in square brackets, such as lucky_numbers[2].

  71. 71

    How can a program change the value of one element in an array?

    1. A

      Use a printf format specifier as the new value.

    2. B

      Assign a new value to the array element at its index.

    3. C

      Change the array's data type to the desired value.

    4. D

      Rename the array to match the new value.

    Correct answer
    B

    Assign a new value to the array element at its index.

    Explanation

    An individual array element can be modified by assigning a new value to that indexed position.

  72. 72

    When an array is declared without an initializer in the described example, what must still be specified?

    1. A

      The number of elements the array can hold.

    2. B

      The number of functions that will use the array.

    3. C

      The value of every element in the array.

    4. D

      The name of every element in the array.

    Correct answer
    A

    The number of elements the array can hold.

    Explanation

    The array's capacity is specified so C can allocate enough memory, even when its elements will be assigned later.

  73. 73

    What does a two-dimensional array contain?

    1. A

      Only one value at each possible index.

    2. B

      Functions as its elements.

    3. C

      Variables of unrelated types at each position.

    4. D

      Arrays as its elements.

    Correct answer
    D

    Arrays as its elements.

    Explanation

    A two-dimensional array is an array whose elements are themselves arrays.

  74. 74

    How are the two indices used to access an element in the demonstrated two-dimensional array?

    1. A

      The first selects a row of code, and the second selects a loop.

    2. B

      The first gives the element's value, and the second gives its format.

    3. C

      The first selects an inner array, and the second selects an element within it.

    4. D

      The first selects a data type, and the second selects a function.

    Correct answer
    C

    The first selects an inner array, and the second selects an element within it.

    Explanation

    In the example, the first index selects one of the arrays inside the outer array, and the second selects an element in that inner array.

  75. 75

    Why does the example use nested loops to visit every element of a two-dimensional array?

    1. A

      One loop assigns data types, while the other names the elements.

    2. B

      One loop selects each inner array, while the other visits its elements.

    3. C

      One loop ends the program, while the other prints the function name.

    4. D

      One loop compiles the array, while the other executes it.

    Correct answer
    B

    One loop selects each inner array, while the other visits its elements.

    Explanation

    The outer loop iterates across the inner arrays, and the inner loop iterates through each inner array's elements.

  76. 76

    What is a structure (struct) useful for representing?

    1. A

      A memory address without any associated data.

    2. B

      A list of values that must all have the same type.

    3. C

      A group of related fields that can have different data types.

    4. D

      A sequence of instructions that executes only once.

    Correct answer
    C

    A group of related fields that can have different data types.

    Explanation

    A structure groups fields, such as a student's name, age, and GPA, even when those fields have different types.

  77. 77

    How does a structure differ from an array in the content's comparison?

    1. A

      A structure holds only characters; an array holds only decimal numbers.

    2. B

      A structure has no elements; an array contains named fields.

    3. C

      A structure can group differently typed, named fields; an array holds same-typed elements.

    4. D

      A structure is used only for functions; an array is used only for files.

    Correct answer
    C

    A structure can group differently typed, named fields; an array holds same-typed elements.

    Explanation

    Structures have named fields that may use different data types, whereas an array's elements share a type and are accessed by index.

  78. 78

    How does the example access the age field of a student structure?

    1. A

      With the structure variable, a dot, and the field name.

    2. B

      With the structure variable and an index in square brackets.

    3. C

      With the field name followed by an ampersand.

    4. D

      With the structure variable and a format specifier.

    Correct answer
    A

    With the structure variable, a dot, and the field name.

    Explanation

    The example uses dot notation, such as student1.age, to access a named structure field.

  79. 79

    Why does the example use strcpy to set a student's name field?

    1. A

      The name is a pointer, and strcpy prints its address.

    2. B

      The name is an integer, and strcpy converts it to a number.

    3. C

      The name field is a function, and strcpy executes it.

    4. D

      The name is a character array, and strcpy copies a string into it.

    Correct answer
    D

    The name is a character array, and strcpy copies a string into it.

    Explanation

    The structure's name field is a character array. The example uses strcpy to copy the desired string into that array.

  80. 80

    What is a function in C?

    1. A

      A condition that determines whether a program compiles.

    2. B

      A variable that can hold only one character.

    3. C

      A data structure whose elements must all be integers.

    4. D

      A named collection of code that performs a task.

    Correct answer
    D

    A named collection of code that performs a task.

    Explanation

    A function groups code for a particular task so that the code can be called when needed.

  81. 81

    What must a program do to execute the code inside a user-defined function?

    1. A

      Call the function.

    2. B

      Place the function inside a comment.

    3. C

      Declare the function as a constant.

    4. D

      Print the function's name.

    Correct answer
    A

    Call the function.

    Explanation

    Defining a function does not execute its body; the program must call the function to run its code.

  82. 82

    What does void indicate as a function's return type in the described example?

    1. A

      The function accepts no parameters.

    2. B

      The function runs only when called from main.

    3. C

      The function does not return information to its caller.

    4. D

      The function can return only a character.

    Correct answer
    C

    The function does not return information to its caller.

    Explanation

    void is used as the return type when the function does not return a value.

  83. 83

    What is a function parameter?

    1. A

      A name given to an array element.

    2. B

      An input value that a function can use.

    3. C

      A value that can only be returned from a function.

    4. D

      A command that ends the function.

    Correct answer
    B

    An input value that a function can use.

    Explanation

    A parameter allows information to be passed into a function so that it can use that information while performing its task.

  84. 84

    If a function is defined to accept a name and an age, what must a call to that function provide?

    1. A

      No arguments, because parameters are optional when called.

    2. B

      Only the age, because the name is inferred.

    3. C

      Only the name, because the age is inferred.

    4. D

      A corresponding name and age argument.

    Correct answer
    D

    A corresponding name and age argument.

    Explanation

    A function call must supply arguments for the parameters that the function is defined to accept.

  85. 85

    What does a function's return type describe?

    1. A

      The type of value the function returns to its caller.

    2. B

      The type of every variable in the program.

    3. C

      The kind of input device the function uses.

    4. D

      The number of times the function is called.

    Correct answer
    A

    The type of value the function returns to its caller.

    Explanation

    A return type identifies the type of information a function gives back to the code that called it.

  86. 86

    What does a return statement do in a value-returning function?

    1. A

      It repeats the function from its first instruction.

    2. B

      It stores the value in every variable in the program.

    3. C

      It sends a value back to the caller and exits the function.

    4. D

      It continues executing all instructions after the return.

    Correct answer
    C

    It sends a value back to the caller and exits the function.

    Explanation

    A return statement provides a value to the caller and ends execution of that function.

  87. 87

    Why is code placed after an executed return statement in the same function body not reached?

    1. A

      The return exits the function immediately.

    2. B

      The return value is printed before the function starts.

    3. C

      The function's parameters prevent later instructions from running.

    4. D

      The compiler converts it into a comment.

    Correct answer
    A

    The return exits the function immediately.

    Explanation

    When execution reaches return, the function ends and control goes back to its caller, so later statements in that function are not executed.

  88. 88

    Why can a function prototype be used before the function's full definition?

    1. A

      It runs the function once to determine its return type.

    2. B

      It replaces the function body with automatically generated code.

    3. C

      It provides values for all future calls to the function.

    4. D

      It declares the function's name, return type, and parameters in advance.

    Correct answer
    D

    It declares the function's name, return type, and parameters in advance.

    Explanation

    A prototype declares the function signature so the compiler knows about the function before it is called in code.

  89. 89

    What is a pointer, in the introductory explanation in the content?

    1. A

      A function that stores a character array.

    2. B

      A special loop that tracks its iteration.

    3. C

      A whole number that cannot be changed.

    4. D

      A value that represents a memory address.

    Correct answer
    D

    A value that represents a memory address.

    Explanation

    The content introduces a pointer as a data value representing a memory address.

  90. 90

    What does the address operator & provide when applied to a variable?

    1. A

      The number of elements the variable can contain.

    2. B

      The value obtained by multiplying the variable by itself.

    3. C

      The memory address where the variable is stored.

    4. D

      A copy of the variable converted into a string.

    Correct answer
    C

    The memory address where the variable is stored.

    Explanation

    The address operator, placed before a variable, gives the memory address where that variable is stored.

  91. 91

    What is the purpose of the * operator when dereferencing a pointer?

    1. A

      It accesses the value stored at the address the pointer refers to.

    2. B

      It increments the pointer's value by one.

    3. C

      It creates a new file at the pointed-to address.

    4. D

      It converts the pointed-to value into a memory address.

    Correct answer
    A

    It accesses the value stored at the address the pointer refers to.

    Explanation

    Dereferencing a pointer with * accesses the value stored at the memory location to which the pointer points.

  92. 92

    If p_age stores the address of an integer variable age, what does *p_age represent?

    1. A

      The integer value stored in age.

    2. B

      The address of the pointer variable p_age.

    3. C

      The number of bytes in the entire program.

    4. D

      The name of the variable age as a string.

    Correct answer
    A

    The integer value stored in age.

    Explanation

    Dereferencing p_age accesses the value at the address it stores; because that address is for an integer, the result is the integer value of age.

  93. 93

    What kind of value does the printf format specifier %p display in the described example?

    1. A

      A string of characters.

    2. B

      A pointer or memory address.

    3. C

      A decimal number.

    4. D

      A single character.

    Correct answer
    B

    A pointer or memory address.

    Explanation

    %p is used to print a pointer value, which represents a memory address.

  94. 94

    What does opening a file with mode w do in the described file examples?

    1. A

      It reads the file without changing it.

    2. B

      It creates a file or writes over an existing file.

    3. C

      It adds new information to the end of an existing file.

    4. D

      It closes the file and releases its pointer.

    Correct answer
    B

    It creates a file or writes over an existing file.

    Explanation

    The w mode is used to write: it creates a file or overwrites an existing file's contents.

  95. 95

    What does opening a file with mode a do?

    1. A

      It erases the file before reading it.

    2. B

      It reads only the first line of the file.

    3. C

      It appends information to the end of the file.

    4. D

      It prevents any new information from being added.

    Correct answer
    C

    It appends information to the end of the file.

    Explanation

    The a mode means append and is used to add information to the end of a file.

  96. 96

    What does opening a file with mode r indicate?

    1. A

      The program intends to read information from the file.

    2. B

      The program intends to overwrite the file.

    3. C

      The program intends to append information to the file.

    4. D

      The program intends to rename the file.

    Correct answer
    A

    The program intends to read information from the file.

    Explanation

    The r mode stands for read and is used when the program wants to obtain information from a file.

  97. 97

    Why should a program close a file after it is finished working with it?

    1. A

      To convert the file's contents into a function.

    2. B

      To finish the file operation and release the file from use in memory.

    3. C

      To append the file contents to the source code.

    4. D

      To prevent the program from accessing any variables.

    Correct answer
    B

    To finish the file operation and release the file from use in memory.

    Explanation

    The content recommends closing files after use; closing completes the file interaction and removes it from use in memory.

  98. 98

    What is the role of the file pointer in the described file operations?

    1. A

      It refers to the file being opened and used.

    2. B

      It decides which C data type the file contains.

    3. C

      It executes each line of the file as a C instruction.

    4. D

      It stores the full contents of the file as an integer.

    Correct answer
    A

    It refers to the file being opened and used.

    Explanation

    The file pointer is used to refer to the opened file when the program reads from or writes to it.

  99. 99

    How does fprintf relate to printf in the described examples?

    1. A

      fprintf closes a file after every character is written.

    2. B

      fprintf writes formatted information to a specified file.

    3. C

      fprintf reads formatted information from the keyboard.

    4. D

      fprintf compiles a file before printf runs.

    Correct answer
    B

    fprintf writes formatted information to a specified file.

    Explanation

    fprintf is similar to printf, but it directs formatted output to the file identified by a file pointer.

  100. 100

    What does the described fgets use do when reading a file?

    1. A

      It reads a line from the file into a character array.

    2. B

      It reads the entire file into an integer variable.

    3. C

      It writes a line from a character array into the file.

    4. D

      It appends a new file to the end of the current file.

    Correct answer
    A

    It reads a line from the file into a character array.

    Explanation

    The example uses fgets to read file contents one line at a time into a character array.

  101. 101

    What happens to the file position as successive fgets calls read lines from a file?

    1. A

      It remains fixed, causing every call to read the same line.

    2. B

      It advances so the next call can read the next line.

    3. C

      It jumps directly to the end of the file after the first call.

    4. D

      It returns to the beginning after every call.

    Correct answer
    B

    It advances so the next call can read the next line.

    Explanation

    After reading a line, the file's current position advances, allowing a subsequent call to read the next line.

Question 1 of 101
Question 1 of 101

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent