Properties of Variables Flashcards
What are the properties of storage duration
- 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
What are the properties(options) of scope
- 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
What aer the properties of linkage?
- 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
What is the default storage duration, scope and linkage of a variable?
What are the properties of the auto storage class?
auto is legal only for variables that belong to a block
has automatic storage duration, block scope and no linkage
What are the properties of the static storage class:
When used outside of a block?
When used inside of a block?
- 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
What are the benefits of the extern storage class?
- 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
What are the properties of register storage class?
- 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
What storage classes can functions have?
- 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);
What are modules made up of?
- 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)
Using linked lists as an example, how do the modules work?
- 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
What are the advantages of dividing a program into modules?
- Abstraction
- Reusability
- Maintainability