Các flashcard này chưa được lưu — chúng sẽ biến mất khi bạn rời đi. Tạo tài khoản miễn phí để giữ lại và mở khóa mọi thứ bên dưới.
What defines the scope of a variable in C?
Scope refers to the visibility of a variable, determining where in the program it can be accessed.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
How long does a variable exist in memory defined as lifetime?
Lifetime refers to how long a variable exists, either during function execution or for the entire duration of the program.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the default storage class for local variables in C?
The default storage class for local variables is auto.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What type of scope can a variable have?
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What keyword is used for auto storage class in C?
The keyword for auto storage class is auto.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What are the four different storage classes in C?
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What does the register storage class suggest?
The register storage class suggests that the variable should be stored in CPU registers for faster access.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What does the static storage class do?
The static storage class retains the variable's value between function calls.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What does visibility refer to in C programming?
Visibility refers to which parts of a program can see and use a variable, which may exist in memory but not be accessible.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
The default storage class for local variables in C is _______.
The default storage class for local variables in C is auto.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
In C, the four storage classes are: _______, _______, _______, _______.
In C, the four storage classes are: auto, register, static, extern.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the scope of an auto variable?
Local to the function where it is declared.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the lifetime of an auto variable?
Exists only while the function is executing.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the default value of an auto variable?
Garbage value (not initialized automatically).
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
Where is the storage location of an auto variable?
RAM (stack memory).
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the purpose of the register storage class?
To define local variables stored in a CPU register for faster access.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the maximum size of a register variable?
Equal to the register size, usually one word.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
Can you use the & operator on a register variable?
No, because it does not have a memory address in RAM.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What happens if no register is available for a register variable?
It will be stored in RAM like a normal variable.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the default value of a register variable?
Garbage value (not initialized automatically).
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the purpose of the register storage class in C?
It is used for variables that are accessed very frequently, like loop counters in nested loops.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What does a static local variable do?
It retains its value between function calls throughout the program's lifetime.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
How does a global static variable differ from a regular global variable?
Its scope is restricted to the file where it is declared, making it inaccessible from other files.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
The static storage class allows local variables to retain their value between function calls. Local static variables _______ even after the function ends.
The static storage class allows local variables to retain their value between function calls. Local static variables retain their value even after the function ends.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
The use of static with global variables restricts their scope to _______ in which they are declared.
The use of static with global variables restricts their scope to the file in which they are declared.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
The register storage class in C is recommended for variables that need to be accessed _______, such as loop counters.
The register storage class in C is recommended for variables that need to be accessed very frequently, such as loop counters.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the initialization value of the global static variable count?
5
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What happens to the local static variable i on subsequent calls to func()?
It retains its previous value and gets incremented.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What would occur if i were a normal auto variable instead of static?
i would be initialized to 5 each time, resulting in the same output for all iterations.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is the lifetime of a local static variable?
It lasts for the entire program execution.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
Where does a static variable's value get stored?
In the data segment of memory, not the stack.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What is a special property of static variables?
They retain their value between function calls.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
In the given program, how many times will func() be called?
5 times, as long as count is greater than 0.
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
The characteristics of static variables include: - Scope: Local to the function (for local static) or local to the file (for global static) - Lifetime: _______ - Default value: _______ - Storage location: _______ - Special property: _______
The characteristics of static variables include: - Scope: Local to the function (for local static) or local to the file (for global static) - Lifetime: entire program execution - Default value: Zero - Storage location: Data segment of memory - Special property: Retains value between function calls
Xem thẻ ở đây, hoặc sign up to study with spaced repetition.
What defines the scope of a variable in C?
Scope refers to the visibility of a variable, determining where in the program it can be accessed.
How long does a variable exist in memory defined as lifetime?
Lifetime refers to how long a variable exists, either during function execution or for the entire duration of the program.
What is the default storage class for local variables in C?
The default storage class for local variables is auto.
What type of scope can a variable have?
What keyword is used for auto storage class in C?
The keyword for auto storage class is auto.
What are the four different storage classes in C?
What does the register storage class suggest?
The register storage class suggests that the variable should be stored in CPU registers for faster access.
What does the static storage class do?
The static storage class retains the variable's value between function calls.
What does visibility refer to in C programming?
Visibility refers to which parts of a program can see and use a variable, which may exist in memory but not be accessible.
The default storage class for local variables in C is auto.
In C, the four storage classes are: auto, register, static, extern.
What is the scope of an auto variable?
Local to the function where it is declared.
What is the lifetime of an auto variable?
Exists only while the function is executing.
What is the default value of an auto variable?
Garbage value (not initialized automatically).
Where is the storage location of an auto variable?
RAM (stack memory).
What is the purpose of the register storage class?
To define local variables stored in a CPU register for faster access.
What is the maximum size of a register variable?
Equal to the register size, usually one word.
Can you use the & operator on a register variable?
No, because it does not have a memory address in RAM.
What happens if no register is available for a register variable?
It will be stored in RAM like a normal variable.
What is the default value of a register variable?
Garbage value (not initialized automatically).
What is the purpose of the register storage class in C?
It is used for variables that are accessed very frequently, like loop counters in nested loops.
What does a static local variable do?
It retains its value between function calls throughout the program's lifetime.
How does a global static variable differ from a regular global variable?
Its scope is restricted to the file where it is declared, making it inaccessible from other files.
The static storage class allows local variables to retain their value between function calls. Local static variables retain their value even after the function ends.
The use of static with global variables restricts their scope to the file in which they are declared.
The register storage class in C is recommended for variables that need to be accessed very frequently, such as loop counters.
What is the initialization value of the global static variable count?
5
What happens to the local static variable i on subsequent calls to func()?
It retains its previous value and gets incremented.
What would occur if i were a normal auto variable instead of static?
i would be initialized to 5 each time, resulting in the same output for all iterations.
What is the lifetime of a local static variable?
It lasts for the entire program execution.
Where does a static variable's value get stored?
In the data segment of memory, not the stack.
What is a special property of static variables?
They retain their value between function calls.
In the given program, how many times will func() be called?
5 times, as long as count is greater than 0.
The characteristics of static variables include: - Scope: Local to the function (for local static) or local to the file (for global static) - Lifetime: entire program execution - Default value: Zero - Storage location: Data segment of memory - Special property: Retains value between function calls
A storage class defines the scope and lifetime of variables/functions in C programs. There are four storage classes: - auto - register - static - extern
Understanding these is crucial as they control the variable's memory and accessibility.
Before diving into storage classes, we need to understand: - Scope: Visibility of a variable in the program (local vs. global). - Lifetime: Duration a variable exists in memory (function execution vs. entire program). - Visibility: Which parts of the program can access the variable.
The auto storage class applies to local variables by default. Variables declared without a storage class are considered auto.
Syntax Examples:
int mount; // auto by default
// or explicitly:
auto int month;
The register storage class suggests storing local variables in a CPU register, which enhances access speed.
Syntax Example:
register int miles;
Important Points: - Used for frequently accessed variables, like loop counters. - Cannot use the & operator due to lack of memory address.
The static storage class preserves a variable's value between function calls. It can be applied to both local and global variables.
#include <stdio.h>
void func(void);
static int count = 5; // global static
int main() {
while(count--) {
func();
}
return 0;
}
void func(void) {
static int i = 5; // local static
i++;
printf("i is %d and count is %d\n", i, count);
}
Output:
i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0
Explanation: Both count and i are static. count decrements each loop iteration, while i retains its value across function calls.
Bạn có chắc chắn muốn xóa 0 flashcard? Hành động này không thể hoàn tác.
Chọn thẻ để gỡ khỏi 0 flashcard đã chọn:
Đang tải thẻ...