Real questions for software designers, special exercises in programming language (2)

Video explanation

Software Designer Morning Questions Programming Topic

basic control structure

The three basic control structures of the program are (33). (First half of 2010)
(33)
A. Process, subroutine and subroutine B. Sequence, Selection and Repetition
C. Recursion, stack and queue D. Call, return and jump

The three basic control structures of programs are sequence structure, selection structure and repetition structure.

General-purpose high-level programming languages ​​generally provide language components for describing data, operations, control and data transmission. Among them, control includes sequence, (20) and loop structures. (First half of 2019)
(20) A. SelectB. Recursion C. Recursion D. Function

The basic controls of programs (algorithms) include sequence, branching (selection) and loop structures.

type of data

Many programming languages ​​stipulate that the data in the program must have a type, and its role does not include (20). (Second half of 2009)
(20)
A. Facilitate reasonable allocation of storage units for data
B. Facilitate participation The data object on which the expression evaluates is checked
C. Convenient to define dynamic data structures
D. It is convenient to specify the value range of data objects and the operations that can be performed

Data has types that allow the compiler to lay out the values ​​on the underlying machine and to check that operations are applied correctly in expressions.

If a programming language stipulates that the data in its program must have types, it is beneficial to (22). (First half of 2011)
① Reasonably allocate storage units for data in the process of translating the program
② Check the data objects involved in expression calculation a>
③ Define and apply dynamic data structures
④ Specify the value range of data objects and the operations that can be performed
⑤ Force the data Type conversion
(22) A. ①②③ B. ①②④ C. ②④⑤ D. ③④⑤

When the data in the program has type attributes, the value range of the data object and the operations that can be performed can be specified, which facilitates type checking before operations and is more conducive to rational allocation of storage units for the data.

A certain programming language stipulates that all data in the source program must have a type. However, (28) is not the reason for this stipulation. (Second half of 2011)
(28)
A. Reasonably allocate storage units for data
B. Can define and use dynamic data structures
C. The value range of data objects and the operations that can be performed can be specified
D. The validity of data objects participating in expression evaluation can be checked

At the machine level, all data is in binary form. The data in the application field can have different forms, meanings and operations. The data in the program must arrange the storage space reasonably. Different types of data spaces, so after specifying the type for the data in the program, the storage space can be arranged more reasonably. Different types of data have different value methods and operations. After the introduction of type information, the validity of the data objects participating in expression evaluation can be checked when compiling the source program. .

During the running of the program, (22) involves the operation of converting integer data into floating-point data. (Second half of 2018)
(22)
A. Assign floating-point variables to integer variables
B. Assign an integer constant to an integer variable
C. Add integer variables and floating point variables
D. Add floating-point constants and floating-point variables

Since integers and real numbers are represented in different ways at the machine level, conversion is required if the data types are different when performing operations or assignments. The general rule is to convert a low-precision or low-digit numeric value into a high-precision or high-digit numeric form.

constant variable

Among the following descriptions of variables and constants, the error is (20). (Second half of 2010)
(20)
A. The value of variables can be changed during the running of the program, but constants cannot
B. Variables have type attributes, but constants do not.
C. Variables have corresponding storage units, but constants do not
D. Variables can be assigned values, but constants cannot be assigned values

A variable is an abstraction of a computer memory unit. It represents data in a program and has attributes such as name, type, value, address, scope, storage class, etc. Its value is modified by instructions during operation. Constants are also used to represent data in programs, but constants cannot be modified while the program is running. Constants also have types, such as integer constants, floating point constants, string constants, etc., which are also called literals or literals.

The following statement about programming languages ​​is incorrect (20). (First half of 2015)
(20)
A. The basic components of programming language include data, operation, control and transmission, etc.
B. High-level programming languages ​​do not depend on specific machine hardware
C. The values ​​of local variables in the program cannot be changed during runtime.
D. The values ​​of constants in the program cannot be changed during runtime.

Option A involves the general concept of programming language. The basic components of programming language include data, operation, control and transmission.
Option B examines the concepts of high-level languages ​​and low-level languages. For programming languages, high-level and low-level languages ​​refer to their level of abstraction relative to the machine on which the program runs. Low-level languages ​​are closer to machine instructions in form, and assembly language corresponds to machine instructions one-to-one. High-level languages ​​abstract and encapsulate underlying operations, and one statement corresponds to multiple machine instructions, making the process of writing programs more in line with human thinking habits and greatly simplifying human labor. High-level languages ​​do not depend on specific machine hardware.
Option C examines the concept of local variables. All variables defined inside a function are local variables (also called internal variables), including variables and function parameters defined in compound statements inside the function. Formal parameters described in the table. Local variables can only be used inside a function, and their scope is from the position of definition to the end of the function body or compound statement body. The value of a local variable usually changes during its lifetime. Option D examines the concept of constants. The values ​​of constants in a program cannot be changed during runtime.

logical expression

For the logical expression "x and y or not z", and, or, and not are logical AND, OR, and NOT operations respectively. The priorities from high to low are not, and, or, and and or are Left combination, not right combination, if short circuit calculation is performed, then (20). (First half of 2012)
(20)
A. When x is true, the value of the entire expression is true, and there is no need to calculate y and z Value
B. When x is false, the value of the entire expression is false, and there is no need to calculate the values ​​of y and z
C. When x is true, determine whether the value of z needs to be calculated based on the value of y
D. When x is false, determine whether the value of z needs to be calculated based on the value of y

Logical expressions can be short-circuited. The basis is: the meaning of a and b is that a and b are "true" at the same time, then a and b are "true". Therefore, if a is "false" , then no matter the value of b is "true" or "false", a and b must be "false"; the meaning of a or b is that a and b are "false" at the same time, then a or b is "false", therefore, If a is "true", then regardless of whether the value of b is "true" or "false", a or b must be "true".
Under the provisions of precedence and associativity, when evaluating the logical expression "x and y or not z", the value of "x andy" should be calculated first. If it is "false", Then calculate the value of "notz". Therefore, if The value of is "true", you need to calculate the value of y: if the value of y is "true", then the value of the entire expression is "true" (so there is no need to calculate "not z"); if the value of y is "false", then "notz" needs to be evaluated to determine the value of the expression.

Logical expression evaluation often uses short-circuit calculation. "&&", "||", and "!" represent logical AND, OR, and NOT operations respectively. "&&" and "||" are left combinations, and "!" are right combinations. The priority is from From high to low are "!", "&&", and "||". When evaluating the logical expression "x&&(y || !z)" in the short-circuit calculation method, (20). (Second half of 2016)
(20)
A. If x is true, then the value of the entire expression is true, and there is no need to calculate y and z value
B. If x is false, then the value of the entire expression is false, and there is no need to calculate the values ​​of y and z.
C. If x is true, then decide whether the value of y needs to be calculated based on the value of z
D. If x is false, then decide whether the value of z needs to be calculated based on the value of y

Logical expressions constructed from "logical AND" and "logical OR" operations can be evaluated using short-circuit calculation. The short-circuit operation logic of the "logical AND" operation "&&" is: a&&b is true if and only if a and b are both true. When a is false, regardless of whether the value of b is true or false, the The value of the expression is false, which means that there is no need to calculate the value of b at this time.
The short-circuit operation logic of "logical OR" operation "II" is: al|[b is false if and only if a and b are both false, when a is true, no matter the value of b is True or false, the value of the expression is true, which means that there is no need to calculate the value of b at this time.
When evaluating the logical expression "x &&(y |l ! z)" in the short-circuit calculation method, if x is false, the value of the entire expression is false, which is not required Calculate the values ​​of y and z. If the value of x is true, then the value of z is determined based on the value of y. If y is true, there is no need to calculate the value of z. If y is false, the value of z needs to be calculated.

Insert image description here

(20) A. d is trueB. a is trueC. b is true D. c is true
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_50843918/article/details/134904879