Class 4: C Storage Class, Scope Linkage Flashcards

1
Q

Storage Class

A

Determines the type of storage and lifetime of storage associated with a variable and the variables initialization if any

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

Storage scope

A

Determines which region of a program in which a variable can be accessed (by name and not through pointer)

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

Linkage

A

Determines whether the same name in a different file frees to the same variables or function or some different variable function

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

Stack

A
  1. A place in memory where information specific to particular function is stored each time it is invoked
  2. It is allocated when the function is called a deal located when he function returns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Heap

A
  1. A place in memory where information specific to a particular process is stored each time it is invoked
  2. Any valuesstored here are available until the process stops executing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Storage class

A

Refers to the type of memory in which a variable values is stored which defines different characteristics for variable

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

Static (keyword)

A

The heap

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

Automatic (keyword)

A

The runtime stack

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

Register (keyword)

A

Hardware registers

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

Do function identifiers have a storage class?

A

NO, they are not stored on the stack or the heap

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

Storage Class: Static

A

Declared outside all blocks.
Retain the last value they were assigned until the program completes

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

What value are storage class static variables automatically assigned to?

A

0

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

Storage Class: Automatic

A

Declared inside a block.

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

When are automatic variables created

A

Just before the execution of the code

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

When are automatic variables discarded

A

When they are not longer accessible/ just as execution leaves the block

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

What storage class do parameters of functions have????

17
Q

Variable declared inside a block but with the keyword static

A

This changes storage class from automatic (the default) to static. Although this changes show long the variable exists during the program, IT DOES NOT CHANGE THE SCOPE STILL BLOCK SCOPE

18
Q

When keyword static is used within a block, it changes a variables ______

A

Storage class

19
Q

When the keyword static is used outside of any/all blocks, it changes an identifiers ________

20
Q

Register variables

A

Stored in machines hardware registers rather than memory. Can be accessed faster. Created and destroyed at the same time as automatic variables

21
Q

Scope

A

Refers to the point in a program in which an identifier may be used to access a variable directly (not through pointer)

22
Q

Block scope

A

Variable can only be accessed within that block

23
Q

File scope

A

Declared outside fo all blocks. The identifier can be accessed anywhere from the end of its declaration to end of the source file in which it was declared

24
Q

Prototype scope

A

Only applies to parameter names DOES not apply to function names

25
Any variables with prototype scope has no _____ or ______
Memory class, linkage This is because no memory has been allocated for the variable
26
Void function2(int var3, int var4);
Function2 : file scope Var3: prototype scope Var4: prototype scope
27
Void function1(int var1, int var2){}
Function1: file scope Var1: block scope Var2: block scope
28
Linkage
Determines how many occurrences of a file scope identifier with the same name (in different files we plan to use together) are treated
29
None linkage
Identifiers that have no linkage (variables without file scope). All block scope variables (NONE) and prototype scope variables (undefined)
30
Internal linkage
All references to the file scope identifier within ONE source file
31
External Linkage
All references to a file scope identifier in any source file refer to the entity
32
What is default linkage of file scope variable?
External
33
How can we change linkage of file scope variable from external to internal
Using the keyword static. This means that no programs except the .c file where the file scope variable is defined can access the variable
34
35
Using a variable with external linkage in another .c file
If you want to use a variable with external linkage in another .c file, you DECLARE it using external. You cannot omit this declaration and use the variable directly.