Properties of Variables Flashcards

1
Q

What are the properties of storage duration

A
  • Automatic - variable is allocated when the surrounding block is executed and deallocated when the block terminates
  • Static - variable stays at the same storage location as long as the program is running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the properties(options) of scope

A
  • Block scope - variable is visibile from its point of declaration until the end of the block
  • File scope - variable is visible frmo its point of delcaration until the end of the enclosing file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What aer the properties of linkage?

A
  • External linkage - variable may be shared with serveral or all files in a program
  • Internal linkage - restricted to a single file and may not be shared
  • No linkage - varialbe belongs to a single function and cannot be shared
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the default storage duration, scope and linkage of a variable?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the properties of the auto storage class?

A

auto is legal only for variables that belong to a block

has automatic storage duration, block scope and no linkage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the properties of the static storage class:

When used outside of a block?

When used inside of a block?

A
  • When used outside a block, static has internal linkage
  • when used inside a block, static changes the storage duration from automatic to static
    • stays within the same storage location throughout program execution
    • shared for all calls of the function
  • Is initialized once prior to program execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the benefits of the extern storage class?

A
  • Allows several source files to share the same variable
  • doesn’t cause memory to be allocated for a variable
  • It tells the compiler that it is defined elsewhere
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the properties of register storage class?

A
  • Asks compiler to store the variable in the CPU register (high-speed storage area in CPU_
  • Compiler is free to store a register variable in memory if it chooses
  • Must be declared in a block
  • same storage duration, scope and linkage as auto
  • cannot use the & operator because it does not have a memory address
  • best used for varialbes that are accessed or updated frequently
    • int i in a for loop is a good candidate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What storage classes can functions have?

A
  • extern - allows it to be called from other files (default)
  • static - limits use of function to the file
    • future modifications won’t affect other files
    • names don’t conflict with other names in other files

static intg(int i);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are modules made up of?

A
  • collection of services(functions), some of which are made available to other parts of the program(the clients)
  • each module has an interface(a header file containing prototypes for the functions) that describes the available services
  • The details of the module - including the source code for the services themselves - are stored in the modules implementation(contains definitions of the module’s functions)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Using linked lists as an example, how do the modules work?

A
  • teamLists.c - main (client of list module)
  • lists.h and lists.c - list module
    • .h is interface of the list module
    • .c is the implementation of the module
  • nodes.h and nodes.c - node module
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the advantages of dividing a program into modules?

A
  • Abstraction
  • Reusability
  • Maintainability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly