C Language Fundamentals Practice Quiz (7 questions)

All questions and answers

1. Which description best identifies the C programming language?

A domain-specific language focused on embedded hardware design
A declarative, functional language designed for database queries
An imperative, procedural, general-purpose programming language
A markup language used to describe operating-system interfaces

An imperative, procedural, general-purpose programming language

Explanation

C is characterized as an imperative, procedural, general-purpose language. Although it is used for embedded systems, it is not a domain-specific language limited to hardware design.

2. Which function is required in a C program and executed first?

A global declaration
The main function
A preprocessor directive
A user-defined function

The main function

Explanation

A C program requires a main function, and it is the first function executed. A user-defined function may be included, but it does not replace main as the program’s entry point.

3. What role does a data type play when a variable is declared in C?

It gives the variable a unique name and determines whether that name is case-sensitive.
It specifies the kind of value the variable can store, its memory requirements, and permitted operations.
It preserves the variable's value between function calls and sets its program lifetime.
It directs the compiler to include a file containing declarations and function definitions.

It specifies the kind of value the variable can store, its memory requirements, and permitted operations.

Explanation

A data type describes the value a variable can hold, the memory needed for it, and the operations that can be performed on it. A variable name identifies a named storage container, but does not determine its type's memory requirements or operations.

4. In the expression `x = 7 + 3 * 2`, which operation is performed first because of C operator precedence?

Multiplication of 3 by 2
Addition of 7 and 3
Assignment of the expression's value to x
Evaluation of the expression from left to right without precedence

Multiplication of 3 by 2

Explanation

Multiplication has higher precedence than addition, so C evaluates `3 * 2` before adding 7, assigning 13 to `x`. Adding first would produce 20, but that does not follow C's precedence rules.

5. How do syntax errors and run-time errors differ in a C program?

Syntax errors violate language rules and are detected during compilation, while run-time errors occur during execution after successful compilation.
Syntax errors arise from uninitialized variables, while run-time errors result from incompatible types detected by the compiler.
Syntax errors occur during execution, while run-time errors are detected during compilation before the program runs.
Syntax errors prevent executable creation during linking, while run-time errors produce incorrect output despite successful execution.

Syntax errors violate language rules and are detected during compilation, while run-time errors occur during execution after successful compilation.

Explanation

A syntax error breaks C language rules and is caught during compilation, whereas a run-time error arises while a successfully compiled program executes. A linker error, rather than a run-time error, prevents the executable from being created.

6. What is the consequence of a linker combining object files produced during C compilation?

The program's variables are assigned values during execution.
A single executable file is created from the object files.
The program's syntax errors are corrected before compilation.
The source code is converted directly into a set of header files.

A single executable file is created from the object files.

Explanation

Linking combines object files to produce a single executable file. Compilation produces the object files, so linking does not directly correct source syntax errors.

7. A function needs to access a global variable that is defined in another source file. Which storage class should be used to declare that variable for access?

static, to give the variable program-wide visibility
auto, to make the variable available across functions
register, to place the variable in a processor register
extern, to refer to the global variable defined elsewhere

extern, to refer to the global variable defined elsewhere

Explanation

The extern storage class refers to a global variable or function defined elsewhere, which supports access across source files. Static on a global variable instead limits its scope to the file where it is declared.

Study with flashcards

Lock in the answers with 10 flashcards on C Language Fundamentals.

Who developed C at Bell Laboratories in 1972, and to write which operating system?

Dennis Ritchie developed C to write UNIX.

What six sections make up a C program?

Documentation, preprocessor directives, definitions, global declarations, the main function, and user-defined functions.

Which four purposes is C used for?

Operating systems, databases, embedded systems, and low-level activities.

See the flashcards →

Read the study guide

Go over the full study guide for C Language Fundamentals.

Read the study guide →

Related classes

Make your own practice quizzes

Upload your class notes and Revizly writes a practice quiz with explained answers in about a minute.

Quiz maker