Programming Systems

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What two rules do you use to decipher complex declarations?

1. Always read declarators from the inside out. In other words, locate the identifier that's being declared, and start deciphering the declaration from there. 2. When there's a choice, always favor [] and () over *. If * precedes the identifier and [] follows it, the identifier represents an array, not a pointer.

What is the integer register file?

Contains 16 named locations storing 64-bit values. These registers can hold addresses (corresponding to C pointers) or integer data.

What are the properties of external variables, also known as global variables.

1. A value stored in an external variable will stay there indefinitely. 2. An external variable can be accessed and potentially modified by all functions that follow its declaration.

What are the benefits of declaring functions to be static?

1. Easier maintenance. Changes to f won't affect functions in other files. 2. Reduced "name space pollution". Since functions declared static have internal linkage, their names can be reused in other files.

Why is it usually better for functions to communicate through parameters rather than by sharing external variables?

1. If we change the external variable during program maintenance, we would need to run through every function to see how the change affects it. 2. If an external variable is assigned an incorrect value, it may be difficult to identify the guilty function. 3. Functions that rely on external variables are hard to reuse in other programs.

What are the advantages of declaring an object to be const?

1. It alerts anyone reading the program to the read-only nature of the object. 2. The compiler can check that the program doesn't inadvertently attempt to change the value of the object. 3. When programs are written for certain types of applications, the compiler can use the word const to identify data to be stored in ROM (read-only memory).

What three properties do every variable have?

1. Storage duration. The storage duration of a variable determines when memory is set aside for the variable and when that memory is released. 2. Scope. The scope of a variable is the portion of the program text in which the variable can be referenced. 3. Linkage. The linkage of a variable determines the extent to which it can be shared by different parts of a program.

What are the values of uninitialized variables?

1. Variables with automatic storage duration have no default initial value. The initial value can't be predicted and may be different each time the variable comes into existence. 2. Variables with static storage duration have the value zero by default. A static variable is correctly initialized based on its type.

What is a local variable and what properties does it have?

A variable declared in the body of a function is said to be local to the function. 1. Local variables have automatic storage duration, which means that storage is automatically allocated when the enclosing function is called and deallocated when the function returns. 2. Local variables also have block scope, which means that it is visible from its point of declaration to the end of the enclosing function body.

What is the program counter?

Commonly referred to as the PC, and called %rip in x86-64, the program counter indicates the address in memory of the next instruction to be executed.

What are declaration specifiers?

Declaration specifiers describe the properties of the variables of functions being declared. There are three types of declaration specifiers: 1. Storage classes: auto, static, extern, and register. 2. Type qualifiers: const and volatile. 3. Type specifiers: void, char, short, int, long, float, double, signed, and unsigned.

What are declarators?

Declarators give the variable its name and may or may not provide additional information about its properties.

What is the storage class of a function?

Function declarations, like variable declarations, may include a storage class, but the only options are extern and static. Functions are extern by default, which means that the function can be called from other files. Static indicated that the function can only be used in the file in which it's defined.

What is an ISA?

Instruction Set Architecture. Fines the format and behavior of a machine-level program.

What does putting static in the declaration of a local variable do?

It causes it to have static storage duration instead of automatic storage duration. A variable with static storage duration has a permanent storage location, so it retains its value throughout the execution of the program. When a function with a static local variable returns, that variable won't lose its value, but it still isn't visible to other functions because of its block scope. It can be used for future calls to this function.

What are the properties of parameters?

Parameters have the same properties as local variables except that each parameter is initialized automatically when a function is called.

What is the auto storage class?

The auto storage class is the default for variables declared inside a block. It has automatic storage duration, block scope, and no linkage.

What is the extern storage class?

The extern storage class enables several source files to share the same variable. If you have a global variable defined in file1, you can access that variable by using "extern" in file2.

What is the register storage class?

The register storage class's storage area is located in the computer's CPU. This class has the same properties as automatic classes, except that you can't access the register's memory address. This class is best used for variables that are accessed and/or updated frequently.

What is the most important scope rule?

When a declaration inside a block names an identifier that's already visible, the new declaration temporarily "hides" the old one, and the identifier takes on a new meaning. At the end of the block, the identifier regains its old meaning.

What is the static storage class and what are some of its properties?

When used outside a block, the word static specifies that a variable has internal linkage (it can't be used in other files). When used inside a block, static changes the variable's storage duration from automatic to static. 1. A static variable in a block is initialized only once, prior to program execution. An auto variable is initialized every time it comes into existence. 2. Each time a function is called recursively, it gets a new set of auto variables. If it has a static variable, on the other hand, that variable is shared by all calls of the function. 3. Although a function shouldn't return a pointer to an auto variable, there's nothing wrong with it returning a pointer to a static variable.

What does the type qualifier "const" do?

const is used to declare objects that resemble variables but are "read-only": a program may access the value of a const object, but can't change it.


संबंधित स्टडी सेट्स

Microeconomics 2106 Final Exam Review

View Set

Intro to Sociology -- Chapter 12

View Set

Practice certificate exam results

View Set

Public Health 10: Stress Management Lesson 14, Public Health 10: Stress Management Lesson 13, UCI Public Health 10: Final Study Guide, Public Health 10

View Set

Operating Environments - UNIX Ch3

View Set

US History "The Great Depression begins"

View Set