C Programming Fundamentals
- 101Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why can learning C provide a useful foundation for learning other programming languages?
Why can learning C provide a useful foundation for learning other programming languages?
101 questions
- 1
Why can learning C provide a useful foundation for learning other programming languages?
- A
Programs written in other languages must first be compiled in C.
- B
C uses the same syntax as all modern programming languages.
- C
C automatically converts programs into every other language.
- D
Many modern programming languages are based on C.
Correct answer
DMany 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++.
- A
- 2
What is the role of a text editor when programming in C?
- A
It allocates memory for every variable in a running program.
- B
It automatically decides the order in which instructions run.
- C
It lets a programmer write and save program text in a file.
- D
It translates program text into instructions the computer executes.
Correct answer
CIt 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.
- A
- 3
What makes an IDE different from a basic text editor, according to the content?
- A
It is a data type used to store program instructions.
- B
It provides a specialized environment for writing, running, and managing programs.
- C
It removes the need to write program instructions in a source file.
- D
It allows a computer to execute C code without compiling it.
Correct answer
BIt 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.
- A
- 4
Why does a C program need to be compiled before the computer can execute it?
- A
The C source must be translated into a form the computer can understand.
- B
The compiler replaces the program's instructions with user input.
- C
The source must be divided into separate variables.
- D
The source file must be converted into a text document.
Correct answer
AThe 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.
- A
- 5
What does building or compiling a C program do, as distinct from running it?
- A
It saves the program's variables to a file.
- B
It translates the C source into code the computer can execute.
- C
It displays all program output in the console.
- D
It tells the computer to execute the translated code.
Correct answer
BIt 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.
- A
- 6
In the described Code::Blocks workflow, what does a build-and-run command do?
- A
It compiles the program and then executes it.
- B
It prints the source code and then saves the output.
- C
It runs the source code first and compiles it afterward.
- D
It edits the source file and then creates a project.
Correct answer
AIt 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.
- A
- 7
What is the purpose of the
mainfunction in a C program?- A
It stores every variable declared in the program.
- B
It displays the program's output without requiring instructions.
- C
It compiles all other functions when they are defined.
- D
It is the function the program executes when it starts.
Correct answer
DIt 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. - A
- 8
What does a
printfinstruction do when execution reaches it?- A
It prints specified information to the screen.
- B
It translates source code into machine instructions.
- C
It repeats the preceding instruction.
- D
It reads a line of text from a file.
Correct answer
AIt prints specified information to the screen.
Explanation
printfis used to print text or other specified information to the screen. - A
- 9
What is a variable in C?
- A
A named container used to store information in a program.
- B
A command that translates a program into machine code.
- C
A function that displays information on the screen.
- D
A condition that determines whether a loop repeats.
Correct answer
AA 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.
- A
- 10
Why can storing a character's name in one variable make a long program easier to maintain?
- A
The name can be changed in one place instead of at every occurrence.
- B
The variable automatically shortens every line that uses the name.
- C
The variable prevents the program from printing the name more than once.
- D
The compiler replaces all other variables with the character's name.
Correct answer
AThe 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.
- A
- 11
Which declaration is appropriate for storing a whole-number age, such as 35?
- A
double age = '35'; - B
int age = 35; - C
char age = 35.0; - D
int age = "35";
Correct answer
Bint age = 35;Explanation
An
intstores an integer, which is a whole number. The content uses an integer variable for a character's age. - A
- 12
Which declaration uses the data type recommended in the content for a beginner storing a GPA such as 3.7?
- A
double gpa = "3.7"; - B
char gpa = '3.7'; - C
int gpa = 3.7; - D
double gpa = 3.7;
Correct answer
Ddouble gpa = 3.7;Explanation
A
doublerepresents a decimal number, and the content recommends usingdoublefor decimal values as a beginner. - A
- 13
What distinguishes the integer value 40 from the double value 40.0 in C?
- A
40 is a double, while 40.0 is an integer.
- B
40 is a string, while 40.0 is a character.
- C
40 is an integer, while 40.0 is a decimal-number value.
- D
40 is a character, while 40.0 is an integer.
Correct answer
C40 is an integer, while 40.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.0, is treated as a decimal value.
- A
- 14
How many individual characters can a basic
charvariable store?- A
One complete line of text.
- B
Any number of characters separated by spaces.
- C
One word of any length.
- D
One character.
Correct answer
DOne character.
Explanation
A
charstores a single character. A sequence of characters requires a character array, such as a string. - A
- 15
How is a string represented in the C examples in the content?
- A
As a single
charholding multiple letters. - B
As a character array.
- C
As a special built-in variable type unrelated to arrays.
- D
As a single integer.
Correct answer
BAs a character array.
Explanation
The content explains that a string is a collection of characters represented using
charand square brackets, making it an array of characters. - A
- 16
Why specify a size such as
20in a character array intended to hold user input?- A
It tells C how many words the user must enter.
- B
It determines how many times the input function will run.
- C
It makes the string automatically expand to any length.
- D
It tells C how much space to allocate for the characters.
Correct answer
DIt 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.
- A
- 17
What does assigning a new value to a variable during execution demonstrate?
- A
A variable can be changed only by a user entering input.
- B
A variable's data type changes automatically with every assignment.
- C
A variable becomes a constant after its first assignment.
- D
A variable's stored value can change as a program runs.
Correct answer
DA 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.
- A
- 18
What is a constant in C, as described in the content?
- A
A number that can be modified only inside a function.
- B
A value declared so that the program cannot modify it.
- C
A data type used exclusively for text.
- D
A variable that changes only when the program is compiled.
Correct answer
BA value declared so that the program cannot modify it.
Explanation
A constant is a value that cannot be modified in the program. The
constkeyword can make a variable constant. - A
- 19
What happens if code attempts to assign a new value to a variable declared with
const?- A
The attempted modification causes an error.
- B
The assignment is silently ignored and execution always continues.
- C
The constant is automatically converted into an ordinary variable.
- D
The program changes the constant only after it has been printed.
Correct answer
AThe attempted modification causes an error.
Explanation
The content demonstrates that modifying a
constvariable produces an error because constants cannot be changed. - A
- 20
Why do developers often write constant variable names in uppercase?
- A
C automatically makes uppercase variables impossible to modify.
- B
Uppercase names prevent the compiler from allocating memory.
- C
It is a convention that makes constants easier to recognize.
- D
C requires uppercase names for every constant.
Correct answer
CIt 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.
- A
- 21
Which format specifier is used in
printfto insert a string into text?- A
%f - B
%d - C
%s - D
%c
Correct answer
C%sExplanation
%sacts as a placeholder for a string of characters inprintf. - A
- 22
Which
printfformat specifier is used to print an integer?- A
%s - B
%d - C
%f - D
%c
Correct answer
B%dExplanation
The content uses
%dto print an integer value. - A
- 23
Which
printfformat specifier is used to print a decimal value such as adouble?- A
%f - B
%c - C
%d - D
%s
Correct answer
A%fExplanation
In the examples,
%fis used inprintfto display a floating-point or decimal value. - A
- 24
Which
printfformat specifier is used to print one character?- A
%s - B
%d - C
%f - D
%c
Correct answer
D%cExplanation
%cis used inprintfto print a single character. - A
- 25
In a
printfcall with several format specifiers, how should the supplied values be arranged?- A
In alphabetical order by variable name.
- B
In any order, because C matches values to variables by name.
- C
In reverse order from the specifiers in the format string.
- D
In the same order as the corresponding specifiers appear in the format string.
Correct answer
DIn 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.
- A
- 26
What does the escape sequence
\ndo when included in text printed byprintf?- A
It terminates the program immediately.
- B
It inserts a tab before the next character.
- C
It prints the two characters backslash and
nliterally. - D
It moves subsequent output to a new line.
Correct answer
DIt moves subsequent output to a new line.
Explanation
\nis a newline character that moves subsequent output onto a new line. - A
- 27
How can a program print a quotation mark as part of a string without ending the string?
- A
Place a semicolon before the quotation mark.
- B
Place a backslash before the quotation mark.
- C
Replace the quotation mark with
%s. - D
Put the quotation mark outside the
printfcall.
Correct answer
BPlace 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.
- A
- 28
What is the basic difference between
printfandscanf?- A
printfcompiles a program, whilescanfexecutes it. - B
printfdisplays information, whilescanfaccepts input. - C
printfreads files, whilescanfwrites files. - D
printfaccepts input, whilescanfdisplays information.
Correct answer
Bprintfdisplays information, whilescanfaccepts input.Explanation
printfprints information to the screen, whereasscanflets the user enter information into the program. - A
- 29
When
scanfstores an integer in an existing variable namedage, what form is used in the example?- A
scanf("%d", &age); - B
scanf("%c", age); - C
scanf("%s", age); - D
scanf("%f", &age);
Correct answer
Ascanf("%d", &age);Explanation
The integer input uses
%d, and&agesupplies the variable's address soscanfcan store the input there. - A
- 30
Which format string does the content use with
scanfto read adouble?- A
%d - B
%s - C
%lf - D
%f
Correct answer
C%lfExplanation
The content distinguishes
scanffromprintf: it uses%lfto scan adouble, whileprintfuses%fto print one. - A
- 31
Which form is used in the content to read a single character into
gradewithscanf?- A
scanf("%d", &grade); - B
scanf("%s", grade); - C
scanf("%f", grade); - D
scanf(" %c", &grade);
Correct answer
Dscanf(" %c", &grade);Explanation
The example uses
%cwith a leading space in the format string and&gradeto read a character. - A
- 32
Why does
scanf("%s", name)stop reading a name such asJohn SmithafterJohn?- A
A space ends the entire program before input is stored.
- B
For a string,
%sstops at the first whitespace. - C
scanfpermits only four characters in every string. - D
The character array automatically deletes text after the first capital letter.
Correct answer
BFor a string,
%sstops at the first whitespace.Explanation
The content explains that
scanfwith%sreads characters only up to the first whitespace. - A
- 33
Why is the address operator
&used with a numeric variable in the describedscanfexamples?- A
It increases the number of characters the variable can store.
- B
It gives
scanfthe variable's address so the function can store input there. - C
It tells
scanfto print the variable before reading input. - D
It converts a numeric value into a string.
Correct answer
BIt gives
scanfthe variable's address so the function can store input there.Explanation
The examples pass the variable's address using
&, allowingscanfto place the entered value into that variable. - A
- 34
Why does the described
scanfexample pass a character array name without&?- A
The array name already refers to the character array's storage.
- B
Character arrays cannot receive input from a user.
- C
The ampersand is used only for output functions.
- D
Strings are printed rather than stored when read by
scanf.
Correct answer
AThe 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
&. - A
- 35
What does
fgetsoffer for reading a line of user text compared with the described%suse ofscanf?- A
It can read a line containing spaces into a character array.
- B
It converts the line directly into an integer.
- C
It prints the line without storing it.
- D
It reads only the first word and discards the rest.
Correct answer
AIt can read a line containing spaces into a character array.
Explanation
fgetsreads a line of text and can therefore capture multiple words separated by spaces. - A
- 36
What is the purpose of the size argument in a call such as
fgets(name, 20, stdin)?- A
It determines the number of times the function is called.
- B
It changes the character array into an integer array.
- C
It limits how many characters the input function accepts.
- D
It specifies how many words must appear on the line.
Correct answer
CIt 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.
- A
- 37
In the described
fgetscall, what doesstdinidentify?- A
The file where the program writes its output.
- B
The memory address of the program's main function.
- C
The maximum number of characters in the array.
- D
The standard input source, such as the console.
Correct answer
DThe standard input source, such as the console.
Explanation
stdinstands for standard input and identifies the source from whichfgetsobtains input, such as the console. - A
- 38
What newline-related behavior should a program account for when using
fgetsto read user input?- A
The newline causes
fgetsto ignore all input after the first word. - B
The Enter key always removes the first character of the stored line.
- C
fgetsconverts the newline into a space before storing the line. - D
The newline created by pressing Enter may be included in the stored line.
Correct answer
DThe 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. - A
- 39
What result does C produce when two integer operands are divided using integer arithmetic, as in 5/4?
- A
The fractional part is discarded, producing the integer 1.
- B
The operation produces the remainder, which is 1.
- C
The operation causes a compilation error.
- D
The result is automatically a double equal to 1.25.
Correct answer
AThe fractional part is discarded, producing the integer 1.
Explanation
When both operands are integers, the result is an integer; in the example, 5/4 produces 1 rather than 1.25.
- A
- 40
What is the result type of an arithmetic operation involving an integer and a floating-point value, according to the content?
- A
A string of digits.
- B
An integer in every case.
- C
A floating-point value.
- D
A character value.
Correct answer
CA floating-point value.
Explanation
The content explains that an operation between an integer and a floating-point number returns a floating-point number.
- A
- 41
Which operator represents multiplication in the arithmetic examples?
- A
/ - B
% - C
+ - D
*
Correct answer
D*Explanation
The examples use an asterisk for multiplication, a forward slash for division, plus for addition, and minus for subtraction.
- A
- 42
What does the C function
pow(2, 3)calculate in the described example?- A
The next integer greater than 2.
- B
2 raised to the third power.
- C
2 multiplied by 3 once.
- D
The square root of 2.
Correct answer
B2 raised to the third power.
Explanation
powtakes a base and an exponent;pow(2, 3)calculates 23, which is 8. - A
- 43
What does the C function
sqrt(36)calculate?- A
The square of 36.
- B
The square root of 36.
- C
The ceiling of 36.
- D
The remainder after dividing 36 by 2.
Correct answer
BThe square root of 36.
Explanation
sqrtreturns the square root of its argument; the example gives 6 forsqrt(36). - A
- 44
What does
ceil(36.3)do in the described examples?- A
Rounds the value downward to the previous integer.
- B
Rounds the value upward to the next integer.
- C
Removes the integer part and keeps the decimal part.
- D
Returns the square root of the value.
Correct answer
BRounds the value upward to the next integer.
Explanation
ceilmeans ceiling and rounds a decimal value upward; the example produces 37 from a value such as 36.3. - A
- 45
What does
floor(36.6)do in the described examples?- A
Rounds the value upward to the higher integer.
- B
Rounds the value downward to the lower integer.
- C
Squares the value and returns a decimal.
- D
Returns the fractional part of the value.
Correct answer
BRounds the value downward to the lower integer.
Explanation
floorrounds a decimal value down; the example produces 36 from a value such as 36.6. - A
- 46
What is a comment in C?
- A
Text in the source code that C ignores during execution.
- B
A statement that prints a note to the console.
- C
A special variable that stores program output.
- D
A function that temporarily pauses compilation.
Correct answer
AText in the source code that C ignores during execution.
Explanation
Comments are marked sections of source code that are ignored when the program runs.
- A
- 47
How can a programmer temporarily prevent a line of code from executing without deleting it?
- A
Place a semicolon before the line.
- B
Place the line inside a comment.
- C
Move the line after the program's final brace.
- D
Rename every variable used by the line.
Correct answer
BPlace the line inside a comment.
Explanation
Commenting out code causes C to ignore it while leaving it in the source file.
- A
- 48
What is a good practice concerning comments, according to the content?
- A
Use comments only to replace executable instructions.
- B
Use them when they are useful or necessary, rather than scattering them everywhere.
- C
Write a comment after every individual character in the program.
- D
Avoid all comments, even when code needs explanation.
Correct answer
BUse 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.
- A
- 49
What does a
whileloop do?- A
Defines a block of code that can be called by name.
- B
Repeats a block of code while its condition remains true.
- C
Executes a block exactly once and then tests its condition.
- D
Selects one matching value from a list of cases.
Correct answer
BRepeats a block of code while its condition remains true.
Explanation
A
whileloop checks its condition and repeatedly executes its body as long as the condition is true. - A
- 50
When is the condition of a
whileloop checked?- A
After the program has exited the loop.
- B
Only after the loop body has executed once.
- C
Only when the program first starts.
- D
Before each execution of the loop body.
Correct answer
DBefore each execution of the loop body.
Explanation
A
whileloop checks its condition before executing the body, including before its first iteration. - A
- 51
What distinguishes a
do-whileloop from awhileloop?- A
A
do-whileloop checks its condition only at program startup. - B
A
do-whileloop cannot repeat its body. - C
A
do-whileloop can contain only one instruction. - D
A
do-whileloop executes its body before checking its condition.
Correct answer
DA
do-whileloop executes its body before checking its condition.Explanation
A
do-whileloop executes its body first, so the body runs at least once before the condition is checked. - A
- 52
What causes an infinite loop in the described
whileloop example?- A
The index starts at a positive value.
- B
The condition is checked before the body runs.
- C
The loop body contains a
printfstatement. - D
The condition stays true because the index is never incremented.
Correct answer
DThe 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.
- A
- 53
What does
index++do in the loop examples?- A
Decreases the value of
indexby one. - B
Sets
indexto zero. - C
Prints the value of
index. - D
Increases the value of
indexby one.
Correct answer
DIncreases the value of
indexby one.Explanation
index++is shorthand for increasing the variable's value by one. - A
- 54
When does an
ifstatement execute the instructions in its body?- A
Every time the program reaches a semicolon.
- B
Only when a function returns a value.
- C
When its condition evaluates to true.
- D
Whenever its condition evaluates to false.
Correct answer
CWhen its condition evaluates to true.
Explanation
An
ifstatement executes its body when the condition is true; otherwise, execution moves past that body. - A
- 55
What role does
elseplay in anif/elsestructure?- A
It defines a condition that must be checked before
if. - B
It repeats the preceding
ifbranch until the condition changes. - C
It returns a value from the function.
- D
It provides a branch to execute when the preceding
ifcondition is false.
Correct answer
DIt provides a branch to execute when the preceding
ifcondition is false.Explanation
The
elseblock runs when the precedingifcondition is false. - A
- 56
What is the purpose of
else ifin a chain of conditions?- A
It defines a loop that repeats while a condition is true.
- B
It makes two conditions both true automatically.
- C
It runs all earlier branches again.
- D
It tests another condition if the preceding condition was false.
Correct answer
DIt tests another condition if the preceding condition was false.
Explanation
else ifprovides an additional condition to test when the earlieriforelse ifcondition was false. - A
- 57
When is the result of a condition joined with
&&true?- A
When at least one condition is true.
- B
Whenever the conditions have different values.
- C
Only when both conditions are false.
- D
When both conditions are true.
Correct answer
DWhen both conditions are true.
Explanation
The logical AND operator
&&makes the combined condition true only when both component conditions are true. - A
- 58
When is the result of a condition joined with
||true?- A
Only when both conditions are false.
- B
When at least one of the conditions is true.
- C
When the two conditions have identical values.
- D
Only when both conditions are true.
Correct answer
BWhen 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. - A
- 59
Which operator checks whether two values are equal in a condition?
- A
!= - B
== - C
= - D
>=
Correct answer
B==Explanation
==compares two values for equality. A single=assigns a value, while!=checks whether values differ. - A
- 60
What does the operator
!=test?- A
Whether one condition and another are both true.
- B
Whether the left value is greater than the right value.
- C
Whether two values are equal.
- D
Whether two values are not equal.
Correct answer
DWhether two values are not equal.
Explanation
!=is the inequality comparison operator; it is true when the compared values are not equal. - A
- 61
What effect does the negation operator
!have when placed before a condition?- A
It assigns a value to the condition.
- B
It joins the condition with another using AND.
- C
It repeats the condition until it changes.
- D
It reverses the condition's truth value.
Correct answer
DIt reverses the condition's truth value.
Explanation
The negation operator reverses a condition: true becomes false, and false becomes true.
- A
- 62
When is a
switchstatement especially useful, as described in the content?- A
When comparing one value against several possible cases.
- B
When translating C code into a form the computer can execute.
- C
When storing multiple values of different types in one variable.
- D
When repeating instructions until a condition becomes false.
Correct answer
AWhen comparing one value against several possible cases.
Explanation
A
switchstatement conveniently compares one value, such as a grade, with several possible case values. - A
- 63
What is the purpose of a
breakat the end of aswitchcase?- A
It converts the case value to a character.
- B
It checks whether the next case matches.
- C
It exits the switch instead of continuing into later cases.
- D
It restarts the switch with the next value.
Correct answer
CIt exits the switch instead of continuing into later cases.
Explanation
breakexits the switch. Without it, execution can continue into the following cases. - A
- 64
When does the
defaultbranch of aswitchexecute?- A
Whenever the first case matches the switch value.
- B
When none of the listed cases matches the switch value.
- C
Before the switch evaluates its value.
- D
After every case, whether or not it matches.
Correct answer
BWhen none of the listed cases matches the switch value.
Explanation
defaultserves as the fallback branch when no listed case matches. - A
- 65
What is the main convenience a
forloop provides over awhileloop in the described counting pattern?- A
It guarantees that the body executes at least once.
- B
It places initialization, the continuation condition, and the update together.
- C
It eliminates the need for a condition.
- D
It automatically prints each value of the index.
Correct answer
BIt places initialization, the continuation condition, and the update together.
Explanation
A
forloop groups the indexing variable's initialization, the loop condition, and its update in the loop header. - A
- 66
In a
forloop that counts from 1 through 5, what does the middle expression specify?- A
The instruction that runs after every iteration.
- B
The value printed when the loop terminates.
- C
The condition that determines whether another iteration runs.
- D
The initial value assigned to the index variable.
Correct answer
CThe condition that determines whether another iteration runs.
Explanation
The middle part of a
forloop header is its continuation condition, such asi <= 5. - A
- 67
Why does the content start an array traversal index at 0?
- A
C array indexing begins at 0, so the first element is at index 0.
- B
C counts array elements backward from the last element.
- C
A loop cannot use an index greater than zero.
- D
The first element of every C array is automatically discarded.
Correct answer
AC array indexing begins at 0, so the first element is at index 0.
Explanation
Array indexing in C starts at 0; thus, an array's first element is accessed with index 0.
- A
- 68
What is an array used for?
- A
Comparing one value against multiple conditions.
- B
Combining several functions into a single instruction.
- C
Storing exactly one value that must be a whole number.
- D
Storing multiple related values in one organized data structure.
Correct answer
DStoring 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.
- A
- 69
What must be true of the elements in a basic C array, as described in the content?
- A
They must all have the same data type.
- B
They must all be named individually.
- C
They must all be initialized by user input.
- D
They must all have different data types.
Correct answer
AThey 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.
- A
- 70
How can a programmer access a particular array element?
- A
Use the array name followed by the element's index in square brackets.
- B
Use the array name followed by the element's value in parentheses.
- C
Use the data type followed by the element's name in braces.
- D
Use the array name followed by a format specifier.
Correct answer
AUse 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]. - A
- 71
How can a program change the value of one element in an array?
- A
Use a
printfformat specifier as the new value. - B
Assign a new value to the array element at its index.
- C
Change the array's data type to the desired value.
- D
Rename the array to match the new value.
Correct answer
BAssign 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.
- A
- 72
When an array is declared without an initializer in the described example, what must still be specified?
- A
The number of elements the array can hold.
- B
The number of functions that will use the array.
- C
The value of every element in the array.
- D
The name of every element in the array.
Correct answer
AThe 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.
- A
- 73
What does a two-dimensional array contain?
- A
Only one value at each possible index.
- B
Functions as its elements.
- C
Variables of unrelated types at each position.
- D
Arrays as its elements.
Correct answer
DArrays as its elements.
Explanation
A two-dimensional array is an array whose elements are themselves arrays.
- A
- 74
How are the two indices used to access an element in the demonstrated two-dimensional array?
- A
The first selects a row of code, and the second selects a loop.
- B
The first gives the element's value, and the second gives its format.
- C
The first selects an inner array, and the second selects an element within it.
- D
The first selects a data type, and the second selects a function.
Correct answer
CThe 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.
- A
- 75
Why does the example use nested loops to visit every element of a two-dimensional array?
- A
One loop assigns data types, while the other names the elements.
- B
One loop selects each inner array, while the other visits its elements.
- C
One loop ends the program, while the other prints the function name.
- D
One loop compiles the array, while the other executes it.
Correct answer
BOne 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.
- A
- 76
What is a structure (
struct) useful for representing?- A
A memory address without any associated data.
- B
A list of values that must all have the same type.
- C
A group of related fields that can have different data types.
- D
A sequence of instructions that executes only once.
Correct answer
CA 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.
- A
- 77
How does a structure differ from an array in the content's comparison?
- A
A structure holds only characters; an array holds only decimal numbers.
- B
A structure has no elements; an array contains named fields.
- C
A structure can group differently typed, named fields; an array holds same-typed elements.
- D
A structure is used only for functions; an array is used only for files.
Correct answer
CA 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.
- A
- 78
How does the example access the age field of a student structure?
- A
With the structure variable, a dot, and the field name.
- B
With the structure variable and an index in square brackets.
- C
With the field name followed by an ampersand.
- D
With the structure variable and a format specifier.
Correct answer
AWith 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. - A
- 79
Why does the example use
strcpyto set a student's name field?- A
The name is a pointer, and
strcpyprints its address. - B
The name is an integer, and
strcpyconverts it to a number. - C
The name field is a function, and
strcpyexecutes it. - D
The name is a character array, and
strcpycopies a string into it.
Correct answer
DThe name is a character array, and
strcpycopies a string into it.Explanation
The structure's name field is a character array. The example uses
strcpyto copy the desired string into that array. - A
- 80
What is a function in C?
- A
A condition that determines whether a program compiles.
- B
A variable that can hold only one character.
- C
A data structure whose elements must all be integers.
- D
A named collection of code that performs a task.
Correct answer
DA 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.
- A
- 81
What must a program do to execute the code inside a user-defined function?
- A
Call the function.
- B
Place the function inside a comment.
- C
Declare the function as a constant.
- D
Print the function's name.
Correct answer
ACall the function.
Explanation
Defining a function does not execute its body; the program must call the function to run its code.
- A
- 82
What does
voidindicate as a function's return type in the described example?- A
The function accepts no parameters.
- B
The function runs only when called from
main. - C
The function does not return information to its caller.
- D
The function can return only a character.
Correct answer
CThe function does not return information to its caller.
Explanation
voidis used as the return type when the function does not return a value. - A
- 83
What is a function parameter?
- A
A name given to an array element.
- B
An input value that a function can use.
- C
A value that can only be returned from a function.
- D
A command that ends the function.
Correct answer
BAn 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.
- A
- 84
If a function is defined to accept a name and an age, what must a call to that function provide?
- A
No arguments, because parameters are optional when called.
- B
Only the age, because the name is inferred.
- C
Only the name, because the age is inferred.
- D
A corresponding name and age argument.
Correct answer
DA corresponding name and age argument.
Explanation
A function call must supply arguments for the parameters that the function is defined to accept.
- A
- 85
What does a function's return type describe?
- A
The type of value the function returns to its caller.
- B
The type of every variable in the program.
- C
The kind of input device the function uses.
- D
The number of times the function is called.
Correct answer
AThe 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.
- A
- 86
What does a
returnstatement do in a value-returning function?- A
It repeats the function from its first instruction.
- B
It stores the value in every variable in the program.
- C
It sends a value back to the caller and exits the function.
- D
It continues executing all instructions after the return.
Correct answer
CIt sends a value back to the caller and exits the function.
Explanation
A
returnstatement provides a value to the caller and ends execution of that function. - A
- 87
Why is code placed after an executed
returnstatement in the same function body not reached?- A
The
returnexits the function immediately. - B
The return value is printed before the function starts.
- C
The function's parameters prevent later instructions from running.
- D
The compiler converts it into a comment.
Correct answer
AThe
returnexits 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. - A
- 88
Why can a function prototype be used before the function's full definition?
- A
It runs the function once to determine its return type.
- B
It replaces the function body with automatically generated code.
- C
It provides values for all future calls to the function.
- D
It declares the function's name, return type, and parameters in advance.
Correct answer
DIt 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.
- A
- 89
What is a pointer, in the introductory explanation in the content?
- A
A function that stores a character array.
- B
A special loop that tracks its iteration.
- C
A whole number that cannot be changed.
- D
A value that represents a memory address.
Correct answer
DA value that represents a memory address.
Explanation
The content introduces a pointer as a data value representing a memory address.
- A
- 90
What does the address operator
&provide when applied to a variable?- A
The number of elements the variable can contain.
- B
The value obtained by multiplying the variable by itself.
- C
The memory address where the variable is stored.
- D
A copy of the variable converted into a string.
Correct answer
CThe memory address where the variable is stored.
Explanation
The address operator, placed before a variable, gives the memory address where that variable is stored.
- A
- 91
What is the purpose of the
*operator when dereferencing a pointer?- A
It accesses the value stored at the address the pointer refers to.
- B
It increments the pointer's value by one.
- C
It creates a new file at the pointed-to address.
- D
It converts the pointed-to value into a memory address.
Correct answer
AIt 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. - A
- 92
If
p_agestores the address of an integer variableage, what does*p_agerepresent?- A
The integer value stored in
age. - B
The address of the pointer variable
p_age. - C
The number of bytes in the entire program.
- D
The name of the variable
ageas a string.
Correct answer
AThe integer value stored in
age.Explanation
Dereferencing
p_ageaccesses the value at the address it stores; because that address is for an integer, the result is the integer value ofage. - A
- 93
What kind of value does the
printfformat specifier%pdisplay in the described example?- A
A string of characters.
- B
A pointer or memory address.
- C
A decimal number.
- D
A single character.
Correct answer
BA pointer or memory address.
Explanation
%pis used to print a pointer value, which represents a memory address. - A
- 94
What does opening a file with mode
wdo in the described file examples?- A
It reads the file without changing it.
- B
It creates a file or writes over an existing file.
- C
It adds new information to the end of an existing file.
- D
It closes the file and releases its pointer.
Correct answer
BIt creates a file or writes over an existing file.
Explanation
The
wmode is used to write: it creates a file or overwrites an existing file's contents. - A
- 95
What does opening a file with mode
ado?- A
It erases the file before reading it.
- B
It reads only the first line of the file.
- C
It appends information to the end of the file.
- D
It prevents any new information from being added.
Correct answer
CIt appends information to the end of the file.
Explanation
The
amode means append and is used to add information to the end of a file. - A
- 96
What does opening a file with mode
rindicate?- A
The program intends to read information from the file.
- B
The program intends to overwrite the file.
- C
The program intends to append information to the file.
- D
The program intends to rename the file.
Correct answer
AThe program intends to read information from the file.
Explanation
The
rmode stands for read and is used when the program wants to obtain information from a file. - A
- 97
Why should a program close a file after it is finished working with it?
- A
To convert the file's contents into a function.
- B
To finish the file operation and release the file from use in memory.
- C
To append the file contents to the source code.
- D
To prevent the program from accessing any variables.
Correct answer
BTo 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.
- A
- 98
What is the role of the file pointer in the described file operations?
- A
It refers to the file being opened and used.
- B
It decides which C data type the file contains.
- C
It executes each line of the file as a C instruction.
- D
It stores the full contents of the file as an integer.
Correct answer
AIt 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.
- A
- 99
How does
fprintfrelate toprintfin the described examples?- A
fprintfcloses a file after every character is written. - B
fprintfwrites formatted information to a specified file. - C
fprintfreads formatted information from the keyboard. - D
fprintfcompiles a file beforeprintfruns.
Correct answer
Bfprintfwrites formatted information to a specified file.Explanation
fprintfis similar toprintf, but it directs formatted output to the file identified by a file pointer. - A
- 100
What does the described
fgetsuse do when reading a file?- A
It reads a line from the file into a character array.
- B
It reads the entire file into an integer variable.
- C
It writes a line from a character array into the file.
- D
It appends a new file to the end of the current file.
Correct answer
AIt reads a line from the file into a character array.
Explanation
The example uses
fgetsto read file contents one line at a time into a character array. - A
- 101
What happens to the file position as successive
fgetscalls read lines from a file?- A
It remains fixed, causing every call to read the same line.
- B
It advances so the next call can read the next line.
- C
It jumps directly to the end of the file after the first call.
- D
It returns to the beginning after every call.
Correct answer
BIt 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.
- A

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