1. What does the term “volatile” signify in C programming?
ⓐ. It indicates a variable that can be modified asynchronously.
ⓑ. It denotes a constant variable.
ⓒ. It signifies a variable that cannot be modified.
ⓓ. It refers to a variable that is not used in the program.
Correct Answer: It indicates a variable that can be modified asynchronously.
Explanation: In C programming, the “volatile” keyword is used to indicate that a variable may be changed unexpectedly by an external entity, such as an interrupt service routine.
2. What does the sizeof() function return in C?
ⓐ. The value of the variable
ⓑ. The number of elements in an array
ⓒ. The size of the variable or type in bytes
ⓓ. The maximum size of a variable
Correct Answer: The size of the variable or type in bytes
Explanation: The sizeof() function in C returns the size of a variable or a data type in bytes, which helps in determining memory requirements.
3. What is the purpose of the keyword “const” in C programming?
ⓐ. It defines a constant value that cannot be changed.
ⓑ. It defines a variable that can only be used once.
ⓒ. It specifies a variable that must be initialized immediately.
ⓓ. It indicates a variable that is used frequently.
Correct Answer: It defines a constant value that cannot be changed.
Explanation: The “const” keyword in C is used to declare constants, which are values that cannot be modified during program execution.
4. What does the function exit() do in C programming?
ⓐ. Terminates the program execution immediately
ⓑ. Prints a message on the console
ⓒ. Pauses the program execution temporarily
ⓓ. Closes all open files
Correct Answer: Terminates the program execution immediately
Explanation: The exit() function in C is used to terminate the program execution immediately and return control to the operating system.
5. What is the role of the “static” keyword in C?
ⓐ. It ensures that variables are initialized to zero.
ⓑ. It restricts the scope of variables to the current file.
ⓒ. It dynamically allocates memory during runtime.
ⓓ. It prevents variables from being accessed by other functions.
Correct Answer: It restricts the scope of variables to the current file.
Explanation: In C programming, the “static” keyword is used to restrict the scope of variables to the current file, making them accessible only within that file.
6. What does the “NULL” pointer represent in C?
ⓐ. An uninitialized pointer
ⓑ. A pointer to the last element of an array
ⓒ. A pointer to a function
ⓓ. A pointer that points to nothing
Correct Answer: A pointer that points to nothing
Explanation: The “NULL” pointer in C represents a pointer that does not point to any memory location. It is commonly used to indicate the end of a data structure or as a sentinel value.
7. What is the purpose of the “typedef” keyword in C programming?
ⓐ. It defines a new data type name for an existing data type.
ⓑ. It creates a new variable.
ⓒ. It specifies a type of file.
ⓓ. It indicates a variable that is used only once.
Correct Answer: It defines a new data type name for an existing data type.
Explanation: The “typedef” keyword in C is used to create a new data type name for an existing data type, which can simplify complex declarations.
8. What is the function of the “do-while” loop in C?
ⓐ. Executes a block of code repeatedly as long as a condition is true
ⓑ. Executes a block of code repeatedly until a condition becomes false
ⓒ. Executes a block of code at least once, then repeats it as long as a condition is true
ⓓ. Executes a block of code exactly once
Correct Answer: Executes a block of code at least once, then repeats it as long as a condition is true
Explanation: The “do-while” loop in C executes a block of code at least once, regardless of whether the condition is true or false, and then repeats the block as long as the condition remains true.
9. What is the purpose of the “inline” keyword in C?
ⓐ. It specifies that a function’s definition is provided in the same file where it is called.
ⓑ. It defines a function that can be called recursively.
ⓒ. It indicates that a function should be optimized for speed.
ⓓ. It ensures that a function is called only once.
Correct Answer: It specifies that a function’s definition is provided in the same file where it is called.
Explanation: The “inline” keyword in C suggests that the compiler should insert the function’s code directly into the calling code, which can improve performance for small, frequently used functions.
10. What does the term “register” signify in C programming?
ⓐ. A storage class specifier that suggests a variable should be stored in a CPU register for faster access.
ⓑ. A keyword that prevents a variable from being modified.
ⓒ. A directive that includes external libraries.
ⓓ. An operator used for memory allocation.
Correct Answer: A storage class specifier that suggests a variable should be stored in a CPU register for faster access.
Explanation: In C programming, the “register” keyword is used as a storage class specifier to suggest that a variable should be stored in a CPU register for faster access, although its use is optional and compilers may ignore it.
11. In C programming, what does “argc” represent?
ⓐ. It stands for argument count and indicates the number of arguments passed to the program.
ⓑ. It stands for argument character and represents the first argument passed to the program.
ⓒ. It stands for array count and specifies the size of an array.
ⓓ. It stands for array character and represents a string array.
Correct Answer: It stands for argument count and indicates the number of arguments passed to the program.
Explanation: “argc” in C programming represents the argument count, which indicates how many arguments (including the program name itself) were passed to the program when it was executed from the command line.
12. What does “argv” represent in C programming?
ⓐ. It stands for argument value and represents the first argument passed to the program.
ⓑ. It stands for array of arguments and points to an array of strings containing the arguments.
ⓒ. It stands for array of values and specifies an array of numerical values.
ⓓ. It stands for array of variables and represents an array of variable declarations.
Correct Answer: It stands for array of arguments and points to an array of strings containing the arguments.
Explanation: “argv” in C programming is an array of strings (char pointers) containing the command line arguments passed to the program, with argv[0] typically being the program’s name.
13. How are command line arguments accessed in C?
ⓐ. Using the “args[]” array
ⓑ. Using the “argc” function
ⓒ. Using the “argv” array
ⓓ. Using the “command()” function
Correct Answer: Using the “argv” array
Explanation: Command line arguments in C are accessed using the “argv” array, where each element of argv[] is a pointer to a string that represents one of the arguments passed to the program.
14. What is the type of “argv” in C programming?
ⓐ. char
ⓑ. int
ⓒ. float
ⓓ. char *
Correct Answer: char *
Explanation: In C programming, “argv” is of type “char *”, which means it is an array of pointers to null-terminated strings (C strings).
15. How is the total number of command line arguments (including the program name) accessed in C?
ⓐ. By using the “argc” function
ⓑ. By counting the elements in the “argv” array
ⓒ. By using the “args[]” array
ⓓ. By accessing the last element of the “argv” array
Correct Answer: By using the “argc” function
Explanation: The total number of command line arguments (including the program name) in C programming is accessed using the “argc” variable, which holds the count of arguments passed to the program.
16. What does “argc” equal if no arguments are passed to a C program from the command line?
ⓐ. 0
ⓑ. 1
ⓒ. -1
ⓓ. NULL
Correct Answer: 1
Explanation: If no arguments are passed to a C program from the command line, “argc” equals 1 because argv[0] holds the program’s name itself.
17. Which header file must be included in a C program to use “argc” and “argv”?
ⓐ. <stdio.h>
ⓑ. <stdlib.h>
ⓒ. <string.h>
ⓓ. <unistd.h>
Correct Answer: <stdio.h>
Explanation: The <stdio.h> header file must be included in a C program to use “argc” and “argv” as they are commonly used for input/output operations and program execution.
18. How can you access the second command line argument passed to a C program?
ⓐ. argv[1]
ⓑ. argv[2]
ⓒ. argv(2)
ⓓ. argv(1)
Correct Answer: argv[1]
Explanation: In C programming, command line arguments are accessed using zero-based indexing, so argv[1] refers to the second command line argument passed to the program.
19. What is the content of argv[0] in a C program?
ⓐ. The program name
ⓑ. The first command line argument
ⓒ. The number of arguments passed
ⓓ. The last command line argument
Correct Answer: The program name
Explanation: In C programming, argv[0] contains the program’s name itself as passed from the command line.
20. How does a C program typically use “argc” and “argv” to process command line arguments?
ⓐ. By iterating through the argv array and checking each argument
ⓑ. By using the argc function to count the number of arguments
ⓒ. By concatenating argc and argv into a single string
ⓓ. By converting argv into an integer value
Correct Answer: By iterating through the argv array and checking each argument
Explanation: A C program typically processes command line arguments by iterating through the argv array and examining each argument individually based on the value of argc.
21. What are environment variables in C programming?
ⓐ. Variables defined within a function
ⓑ. Variables defined globally in a program
ⓒ. Variables passed from the command line
ⓓ. Variables external to the program that affect its behavior
Correct Answer: Variables external to the program that affect its behavior
Explanation: Environment variables in C programming are variables external to the program that can affect its behavior, such as configuration settings or system parameters.
22. How can you access environment variables in C?
ⓐ. Using the getenv() function
ⓑ. Using the scanf() function
ⓒ. Using the printf() function
ⓓ. Using the setenv() function
Correct Answer: Using the getenv() function
Explanation: In C programming, environment variables are accessed using the getenv() function, which retrieves the value of a specified environment variable.
23. Which header file must be included to use the getenv() function in C?
ⓐ. <stdio.h>
ⓑ. <stdlib.h>
ⓒ. <string.h>
ⓓ. <unistd.h>
Correct Answer: <stdlib.h>
Explanation: The <stdlib.h> header file must be included in a C program to use the getenv() function as it provides functions for manipulating the environment.
24. What does the setenv() function do in C programming?
ⓐ. Retrieves the value of an environment variable
ⓑ. Sets the value of an environment variable
ⓒ. Prints the value of an environment variable
ⓓ. Deletes an environment variable
Correct Answer: Sets the value of an environment variable
Explanation: The setenv() function in C programming sets the value of an environment variable or creates a new one if it doesn’t exist.
25. Which function deletes an environment variable in C programming?
ⓐ. deleteenv()
ⓑ. unsetenv()
ⓒ. envdelete()
ⓓ. clearenv()
Correct Answer: unsetenv()
Explanation: In C programming, the unsetenv() function deletes an environment variable by removing its definition.
26. What is the purpose of the “environ” variable in C programming?
ⓐ. It stores the environment variables as an array of strings.
ⓑ. It stores the command line arguments as an array of strings.
ⓒ. It stores the current working directory.
ⓓ. It stores the exit status of the program.
Correct Answer: It stores the environment variables as an array of strings.
Explanation: The “environ” variable in C programming is an external variable that contains the environment variables as an array of strings (char *).
27. How does a C program access all environment variables?
ⓐ. By using the env() function
ⓑ. By iterating through the argv array
ⓒ. By using the getenv() function iteratively
ⓓ. By accessing the “environ” variable
Correct Answer: By accessing the “environ” variable
Explanation: A C program accesses all environment variables by iterating through the “environ” variable, which contains the environment variables as an array of strings.
28. Which environment variable contains the path to the user’s home directory?
ⓐ. HOME
ⓑ. PATH
ⓒ. USER
ⓓ. SHELL
Correct Answer: HOME
Explanation: In C programming, the HOME environment variable typically contains the path to the user’s home directory.
29. What happens if an environment variable is not found using getenv() in C?
ⓐ. The program terminates
ⓑ. The function returns NULL
ⓒ. The function returns an empty string
ⓓ. The program enters an infinite loop
Correct Answer: The function returns NULL
Explanation: If an environment variable is not found using the getenv() function in C programming, the function returns NULL.
30. How can a C program modify the value of an environment variable?
ⓐ. By using the setenv() function
ⓑ. By using the getenv() function
ⓒ. By using the envset() function
ⓓ. By using the changeenv() function
Correct Answer: By using the setenv() function
Explanation: In C programming, the value of an environment variable can be modified using the setenv() function, which sets or updates the value of an existing environment variable.
31. What does the following C program output when compiled and executed?
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
for (i = 0; i < argc; i++) {
printf("Argument %d: %s\n", i, argv[i]);
}
return 0;
}
ⓐ. It prints all command line arguments passed to the program.
ⓑ. It prints the number of command line arguments passed.
ⓒ. It prints the program name and the first command line argument.
ⓓ. It prints nothing due to a compilation error.
Correct Answer: It prints all command line arguments passed to the program.
Explanation: This program uses a loop to iterate through all command line arguments (including the program name) and prints each argument along with its index.
32. What does the following command line input do when executed?
./program arg1 "argument 2" arg3
ⓐ. Executes the program with three arguments.
ⓑ. Executes the program with one argument.
ⓒ. Prints "program arg1 argument 2 arg3".
ⓓ. Prints "arg1 argument 2 arg3".
Correct Answer: Executes the program with three arguments.
Explanation: This command executes the program named "program" with three command line arguments: "arg1", "argument 2" (which is enclosed in double quotes), and "arg3".
33. What does the "argc" variable contain in the context of the main function?
ⓐ. The number of command line arguments passed to the program.
ⓑ. The first command line argument passed to the program.
ⓒ. The last command line argument passed to the program.
ⓓ. The program name itself.
Correct Answer: The number of command line arguments passed to the program.
Explanation: In C programming, "argc" contains the number of command line arguments passed to the program, including the program name itself.
34. Which statement correctly retrieves the second command line argument passed to a C program?
ⓐ. `argv[1]`
ⓑ. `argv[2]`
ⓒ. `argv[0]`
ⓓ. `argc[1]`
Correct Answer: `argv[1]`
Explanation: Command line arguments in C programming are accessed using the `argv` array, with `argv[0]` containing the program's name, `argv[1]` containing the first argument, `argv[2]` containing the second argument, and so on.
35. What is the purpose of using double quotes around a command line argument?
ⓐ. To prevent the argument from being printed.
ⓑ. To treat the argument as a string literal.
ⓒ. To ignore the argument during program execution.
ⓓ. To indicate a comment within the argument.
Correct Answer: To treat the argument as a string literal.
Explanation: In C programming, double quotes around a command line argument indicate that the argument should be treated as a single string literal, even if it contains spaces or special characters.
36. What happens if a C program is executed without any command line arguments?
ⓐ. It terminates with an error.
ⓑ. It prints a message and waits for input.
ⓒ. It executes normally with argc equal to 1.
ⓓ. It enters an infinite loop.
Correct Answer: It executes normally with argc equal to 1.
Explanation: If a C program is executed without any command line arguments, `argc` is equal to 1 because it counts the program name itself as the first argument.
37. Which function is used to retrieve the value of an environment variable in C?
ⓐ. `getenv()`
ⓑ. `setenv()`
ⓒ. `envvar()`
ⓓ. `retrieveenv()`
Correct Answer: `getenv()`
Explanation: The `getenv()` function in C programming is used to retrieve the value of an environment variable by providing its name as an argument.
38. What does the following code snippet do?
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s \n", argv[0]);
return 1;
}
printf("Argument provided: %s\n", argv[1]);
return 0;
}
ⓐ. Prints the first command line argument.
ⓑ. Prints the program name and exits if no argument is provided.
ⓒ. Prints all command line arguments.
ⓓ. Prints nothing due to a compilation error.
Correct Answer: Prints the program name and exits if no argument is provided.
Explanation: This program checks if at least two arguments (including the program name) are provided. If not, it prints a usage message and exits with a non-zero status.
39. What is the significance of `argv[0]` in a C program?
ⓐ. It stores the last command line argument.
ⓑ. It stores the program name.
ⓒ. It stores the total number of arguments.
ⓓ. It stores the first command line argument.
Correct Answer: It stores the program name.
Explanation: In C programming, `argv[0]` stores the program name itself, which is always the first element in the `argv` array.
40. Which statement is true about command line arguments in C?
ⓐ. They are automatically converted to integers.
ⓑ. They can only be accessed through standard input functions.
ⓒ. They are passed as strings.
ⓓ. They cannot be modified once passed.
Correct Answer: They are passed as strings.
Explanation: Command line arguments in C programming are passed as an array of strings (`char *argv[]`), where each argument is treated as a null-terminated string.
41. What is the main difference between local and global variables in C programming?
ⓐ. Local variables are declared inside functions, while global variables are declared outside functions.
ⓑ. Global variables are initialized automatically, while local variables need explicit initialization.
ⓒ. Local variables have a smaller scope than global variables.
ⓓ. Global variables cannot be modified once initialized.
Correct Answer: Local variables are declared inside functions, while global variables are declared outside functions.
Explanation: Local variables are declared within a function and have a local scope, while global variables are declared outside of any function and have a global scope accessible throughout the program.
42. Which of the following statements is true regarding the scope of local variables in C?
ⓐ. Local variables can be accessed from any function in the program.
ⓑ. Local variables are accessible only within the function where they are declared.
ⓒ. Local variables are accessible within the file where they are declared.
ⓓ. Local variables are accessible in all functions of the same name.
Correct Answer: Local variables are accessible only within the function where they are declared.
Explanation: Local variables in C programming are accessible only within the block or function where they are declared. They are not visible or accessible outside their scope.
43. In C programming, where are global variables typically declared?
ⓐ. Inside functions
ⓑ. Inside conditional statements
ⓒ. Outside all functions, at the beginning of the program
ⓓ. Inside header files
Correct Answer: Outside all functions, at the beginning of the program
Explanation: Global variables in C programming are typically declared outside all functions, usually at the beginning of the program before any function definitions.
44. Which of the following statements is true about the lifetime of global variables in C?
ⓐ. Global variables are destroyed when the program exits.
ⓑ. Global variables are destroyed when the function where they are declared exits.
ⓒ. Global variables exist until the end of the block where they are declared.
ⓓ. Global variables are automatically deallocated when not in use.
Correct Answer: Global variables are destroyed when the program exits.
Explanation: Global variables in C programming have a lifetime that extends throughout the entire execution of the program. They are destroyed when the program terminates.
45. What happens if a local variable shares the same name as a global variable in C?
ⓐ. The compiler throws an error.
ⓑ. The global variable takes precedence over the local variable.
ⓒ. The local variable takes precedence over the global variable.
ⓓ. Both variables are destroyed.
Correct Answer: The local variable takes precedence over the global variable.
Explanation: In C programming, if a local variable and a global variable share the same name, the local variable takes precedence over the global variable within the scope of the local variable.
46. Which of the following statements correctly describes the initialization of global variables in C?
ⓐ. Global variables must be initialized at the point of declaration.
ⓑ. Global variables are initialized automatically with a default value of 0.
ⓒ. Global variables are not initialized by default and need explicit initialization.
ⓓ. Global variables are initialized with the value of the first command line argument.
Correct Answer: Global variables are initialized automatically with a default value of 0.
Explanation: In C programming, global variables that are not explicitly initialized are automatically initialized with the value 0 (zero).
47. What is the primary advantage of using local variables over global variables in C?
ⓐ. Local variables have a longer lifetime.
ⓑ. Local variables conserve memory.
ⓒ. Local variables can be accessed from any function.
ⓓ. Local variables are easier to debug.
Correct Answer: Local variables conserve memory.
Explanation: Local variables in C programming are allocated memory only when their containing function is called and deallocated when the function exits, thus conserving memory compared to global variables which exist throughout the program's execution.
48. Which of the following is a disadvantage of using global variables in C programming?
ⓐ. Global variables have a longer lifetime.
ⓑ. Global variables can be accessed only within the function where they are declared.
ⓒ. Global variables increase the risk of naming conflicts.
ⓓ. Global variables are automatically initialized.
Correct Answer: Global variables increase the risk of naming conflicts.
Explanation: Global variables in C programming are accessible throughout the entire program, increasing the risk of unintentional name conflicts and making the program less modular and harder to maintain.
49. In C programming, can the value of a global variable be changed by a function?
ⓐ. Yes, by using the `static` keyword.
ⓑ. No, global variables cannot be modified once initialized.
ⓒ. Yes, by passing it as an argument to the function.
ⓓ. No, global variables are read-only.
Correct Answer: Yes, by using the `static` keyword.
Explanation: Global variables in C programming can be modified by functions directly if they are not declared as `const` or if they are not declared with the `static` keyword, which limits their scope to the file where they are declared.
50. What happens if a global variable is declared inside a function in C programming?
ⓐ. It becomes a local variable of that function.
ⓑ. It cannot be accessed outside the function.
ⓒ. It automatically becomes a constant.
ⓓ. It is automatically initialized to 0.
Correct Answer: It becomes a local variable of that function.
Explanation: If a variable is declared inside a function in C programming without the `static` keyword, it becomes a local variable of that function, not a global variable. It is accessible only within the scope of that function.
51. What is the primary characteristic of static variables in C programming?
ⓐ. They can only be accessed within the function where they are declared.
ⓑ. They retain their value between function calls.
ⓒ. They are automatically initialized to zero.
ⓓ. They are declared using the `auto` keyword.
Correct Answer: They retain their value between function calls.
Explanation: Static variables in C programming retain their value between function calls, unlike local variables which are re-initialized each time the function is called.
52. Which keyword is used to declare a static variable in C?
ⓐ. static
ⓑ. auto
ⓒ. const
ⓓ. extern
Correct Answer: static
Explanation: Static variables in C are declared using the `static` keyword. This keyword specifies that the variable retains its value between function calls.
53. Where are static variables stored in memory?
ⓐ. Stack
ⓑ. Heap
ⓒ. Data segment
ⓓ. Code segment
Correct Answer: Data segment
Explanation: Static variables in C programming are stored in the data segment of memory, along with global variables. They are initialized once and retain their value throughout the program's execution.
54. What is the initial value of a static variable in C if not explicitly initialized?
ⓐ. 0
ⓑ. 1
ⓒ. Undefined
ⓓ. Depends on the compiler
Correct Answer: 0
Explanation: Static variables in C programming are automatically initialized to zero if not explicitly initialized by the programmer.
55. Which statement is true regarding the scope of static variables in C?
ⓐ. Static variables have global scope.
ⓑ. Static variables have local scope.
ⓒ. Static variables have block scope.
ⓓ. Static variables have no scope.
Correct Answer: Static variables have block scope.
Explanation: Static variables in C programming have block scope, meaning they are accessible only within the block or function where they are declared.
56. What is the purpose of using static variables in C programming?
ⓐ. To conserve memory by reusing variable names.
ⓑ. To restrict access to the variable within a specific function.
ⓒ. To retain the variable's value between function calls.
ⓓ. To declare constants that cannot be modified.
Correct Answer: To retain the variable's value between function calls.
Explanation: One of the primary purposes of using static variables in C programming is to retain their value between successive function calls, providing persistence across function invocations.
57. Which statement correctly describes the lifecycle of static variables in C?
ⓐ. Static variables are destroyed when the program exits.
ⓑ. Static variables are destroyed when the function where they are declared exits.
ⓒ. Static variables exist until explicitly deallocated using free().
ⓓ. Static variables are never destroyed.
Correct Answer: Static variables are destroyed when the program exits.
Explanation: Static variables in C programming have a lifetime that extends throughout the entire execution of the program. They are destroyed when the program terminates.
58. Can static variables be initialized multiple times within the same function in C?
ⓐ. Yes, using the `initialize` keyword.
ⓑ. No, static variables can only be initialized once.
ⓒ. Yes, using the `static` keyword.
ⓓ. No, static variables are automatically initialized.
Correct Answer: No, static variables can only be initialized once.
Explanation: Static variables in C programming can only be initialized once, typically when they are declared. Subsequent initializations within the same function are ignored.
59. In C programming, can static variables be accessed from outside the function where they are declared?
ⓐ. Yes, by using the extern keyword.
ⓑ. No, static variables have local scope.
ⓒ. Yes, by using the static keyword.
ⓓ. No, static variables are inaccessible outside their function.
Correct Answer: No, static variables have local scope.
Explanation: Static variables in C programming have local scope, meaning they are accessible only within the function where they are declared and not from outside that function.
60. Which of the following is a correct way to declare a static variable named "count" of type int in C?
ⓐ. `count static int;`
ⓑ. `int count = static;`
ⓒ. `static int count;`
ⓓ. `static count int;`
Correct Answer: `static int count;`
Explanation: The correct syntax to declare a static variable named "count" of type int in C is `static int count;`. This declares "count" as a static variable with block scope.
61. What is the primary purpose of using register variables in C programming?
ⓐ. To allocate memory in the register file of the CPU.
ⓑ. To allocate memory in the heap instead of the stack.
ⓒ. To declare variables as constants.
ⓓ. To optimize the access speed of variables.
Correct Answer: To optimize the access speed of variables.
Explanation: Register variables in C programming are used to optimize the access speed of frequently accessed variables by storing them in CPU registers instead of memory.
62. Which keyword is used to declare a register variable in C?
ⓐ. register
ⓑ. static
ⓒ. auto
ⓓ. volatile
Correct Answer: register
Explanation: Register variables in C programming are declared using the `register` keyword. This suggests to the compiler that the variable should be stored in a CPU register for faster access.
63. What is the maximum number of register variables that can be declared in a C function?
ⓐ. It depends on the size of the CPU registers.
ⓑ. It depends on the compiler implementation.
ⓒ. It depends on the amount of available memory.
ⓓ. It depends on the function's return type.
Correct Answer: It depends on the compiler implementation.
Explanation: The maximum number of register variables that can be declared in a C function depends on the compiler implementation and the architecture. Typically, compilers optimize register allocation automatically.
64. Which statement is true regarding the scope of register variables in C?
ⓐ. Register variables have global scope.
ⓑ. Register variables have local scope.
ⓒ. Register variables have block scope.
ⓓ. Register variables have no scope.
Correct Answer: Register variables have block scope.
Explanation: Register variables in C programming have block scope, meaning they are accessible only within the block or function where they are declared.
65. Can the address of a register variable be obtained in C programming?
ⓐ. Yes, using the & operator.
ⓑ. No, register variables do not have addresses.
ⓒ. Yes, using the sizeof operator.
ⓓ. No, register variables are automatically deallocated.
Correct Answer: Yes, using the & operator.
Explanation: In C programming, the address of a register variable can be obtained using the `&` operator, although it may not always be meaningful or supported by the compiler.
66. Which of the following statements is true about register variables in C?
ⓐ. Register variables can only be of type int.
ⓑ. Register variables are always automatically initialized to 0.
ⓒ. Register variables are stored in the CPU cache.
ⓓ. Register variables cannot be used in functions that call other functions.
Correct Answer: Register variables are stored in the CPU cache.
Explanation: Register variables in C programming are stored in CPU registers or cache memory for faster access, optimizing performance compared to variables stored in RAM.
67. What happens if the number of register variables declared in a function exceeds the number of available CPU registers?
ⓐ. The program throws a runtime error.
ⓑ. The excess register variables are automatically promoted to global variables.
ⓒ. The excess register variables are treated as static variables.
ⓓ. The compiler ignores the register keyword for those variables.
Correct Answer: The compiler ignores the register keyword for those variables.
Explanation: If the number of register variables declared in a function exceeds the number of available CPU registers, the compiler may ignore the `register` keyword for those variables, treating them as regular variables stored in memory.
68. In C programming, which type of variables are typically candidates for declaration as register variables?
ⓐ. Variables used infrequently within a function.
ⓑ. Variables passed as arguments to functions.
ⓒ. Variables used frequently within a function.
ⓓ. Variables declared as global variables.
Correct Answer: Variables used frequently within a function.
Explanation: Register variables in C programming are typically used for variables that are accessed frequently within a function, aiming to optimize the speed of access by storing them in CPU registers.
69. Which of the following is a disadvantage of using register variables in C programming?
ⓐ. They consume more memory than regular variables.
ⓑ. They are slower to access compared to regular variables.
ⓒ. They cannot be passed as arguments to functions.
ⓓ. Their usage is limited to functions with a single return statement.
Correct Answer: They consume more memory than regular variables.
Explanation: Register variables in C programming may consume more memory than regular variables due to their storage in CPU registers or cache, which are limited in size.
70. Which statement correctly describes the initialization of register variables in C?
ⓐ. Register variables must be explicitly initialized at the point of declaration.
ⓑ. Register variables are automatically initialized to zero.
ⓒ. Register variables cannot be initialized with non-constant values.
ⓓ. Register variables are initialized with the value of the first command line argument.
Correct Answer: Register variables must be explicitly initialized at the point of declaration.
Explanation: Register variables in C programming must be explicitly initialized at the point of declaration, as the `register` keyword does not imply automatic initialization.
71. What is the primary purpose of the `extern` keyword in C programming?
ⓐ. To declare global variables.
ⓑ. To declare local variables.
ⓒ. To specify external linkage of variables or functions.
ⓓ. To declare constants.
Correct Answer: To specify external linkage of variables or functions.
Explanation: The `extern` keyword in C programming is used to declare variables or functions that are defined in another file and specify their external linkage.
72. Where is the `extern` keyword typically used in C programming?
ⓐ. Inside function definitions.
ⓑ. Inside conditional statements.
ⓒ. Inside header files.
ⓓ. Outside function definitions.
Correct Answer: Outside function definitions.
Explanation: The `extern` keyword in C programming is typically used outside function definitions, usually at the beginning of source files or header files, to declare variables or functions with external linkage.
73. Which of the following statements is true regarding the storage allocation of `extern` variables in C?
ⓐ. `extern` variables are allocated storage when they are declared.
ⓑ. `extern` variables are allocated storage only when they are defined.
ⓒ. `extern` variables are allocated storage in the data segment.
ⓓ. `extern` variables are allocated storage in the heap.
Correct Answer: `extern` variables are allocated storage only when they are defined.
Explanation: `extern` variables in C programming are declared to have external linkage but are not allocated storage when declared with `extern`. Storage allocation occurs when the variable is defined elsewhere in the program.
74. In C programming, what happens if an `extern` variable is declared multiple times across different files?
ⓐ. The compiler throws an error.
ⓑ. Each declaration allocates separate storage.
ⓒ. All declarations refer to the same storage.
ⓓ. The first declaration takes precedence.
Correct Answer: All declarations refer to the same storage.
Explanation: In C programming, multiple `extern` declarations of the same variable across different files refer to the same storage location where the variable is defined.
75. Which statement is true about the initialization of `extern` variables in C?
ⓐ. `extern` variables must be initialized at the point of declaration.
ⓑ. `extern` variables are automatically initialized to zero.
ⓒ. `extern` variables cannot be initialized.
ⓓ. `extern` variables are initialized with the value of the first command line argument.
Correct Answer: `extern` variables must be initialized at the point of declaration.
Explanation: `extern` variables in C programming must be initialized at the point of definition, not at the point of declaration. The `extern` keyword only declares the existence of a variable with external linkage.
76. Which keyword is often used together with `extern` to access global variables across different files in C programming?
ⓐ. static
ⓑ. auto
ⓒ. const
ⓓ. none of the above
Correct Answer: none of the above
Explanation: The `extern` keyword itself is used to access global variables across different files in C programming. It does not require any other keyword for this purpose.
77. What is the scope of `extern` variables in C programming?
ⓐ. Global to the file where they are declared.
ⓑ. Local to the function where they are declared.
ⓒ. Global to all functions within the file.
ⓓ. Global to the entire program.
Correct Answer: Global to the entire program.
Explanation: `extern` variables in C programming have global scope, meaning they can be accessed and used throughout the entire program once they are declared.
78. Which statement is true regarding the linkage of `extern` variables in C programming?
ⓐ. `extern` variables have internal linkage by default.
ⓑ. `extern` variables have external linkage by default.
ⓒ. The linkage of `extern` variables depends on their storage class.
ⓓ. `extern` variables cannot have linkage.
Correct Answer: `extern` variables have external linkage by default.
Explanation: `extern` variables in C programming have external linkage by default, meaning they can be accessed from other files when properly declared.
79. In C programming, can `extern` be used to declare a function?
ⓐ. Yes, to specify that the function is defined in another file.
ⓑ. No, `extern` cannot be used with functions.
ⓒ. Yes, to declare a function as static.
ⓓ. No, functions are automatically declared as extern.
Correct Answer: Yes, to specify that the function is defined in another file.
Explanation: In C programming, the `extern` keyword can be used to declare functions to specify that they are defined in another file and have external linkage.
80. Which of the following is a correct way to declare an `extern` variable named "count" of type int in C?
ⓐ. `extern count int;`
ⓑ. `count extern int;`
ⓒ. `int count extern;`
ⓓ. `extern int count;`
Correct Answer: `extern int count;`
Explanation: The correct syntax to declare an `extern` variable named "count" of type int in C is `extern int count;`. This declares "count" as an `extern` variable with external linkage.
81. What is the scope of a local variable in C programming?
ⓐ. Global to the file where it is declared.
ⓑ. Local to the function where it is declared.
ⓒ. Global to all functions within the file.
ⓓ. Global to the entire program.
Correct Answer: Local to the function where it is declared.
Explanation: Local variables in C programming have scope limited to the function where they are declared. They are not accessible outside of that function.
82. Which statement accurately describes the lifetime of a local variable in C?
ⓐ. Local variables are destroyed when the program exits.
ⓑ. Local variables are destroyed when the function where they are declared exits.
ⓒ. Local variables persist throughout the entire program execution.
ⓓ. Local variables are never destroyed.
Correct Answer: Local variables are destroyed when the function where they are declared exits.
Explanation: Local variables in C programming are destroyed (their memory is freed) when the function where they are declared exits. They do not persist beyond the function's execution.
83. What is the scope of a global variable in C programming?
ⓐ. Local to the function where it is declared.
ⓑ. Global to the file where it is declared.
ⓒ. Global to all functions within the file.
ⓓ. Global to the entire program.
Correct Answer: Global to the entire program.
Explanation: Global variables in C programming have scope that extends throughout the entire program. They can be accessed and modified by any function or file in the program.
84. Which statement accurately describes the lifetime of a global variable in C?
ⓐ. Global variables are destroyed when the program exits.
ⓑ. Global variables are destroyed when the function where they are declared exits.
ⓒ. Global variables persist throughout the entire program execution.
ⓓ. Global variables are never destroyed.
Correct Answer: Global variables are destroyed when the program exits.
Explanation: Global variables in C programming persist throughout the entire program execution and are destroyed when the program terminates.
85. What is the scope of a static variable in C programming?
ⓐ. Global to the file where it is declared.
ⓑ. Local to the function where it is declared.
ⓒ. Global to all functions within the file.
ⓓ. Global to the entire program.
Correct Answer: Global to all functions within the file.
Explanation: Static variables in C programming have scope that extends to all functions within the file where they are declared. They are not visible outside that file.
86. Which statement accurately describes the lifetime of a static variable in C?
ⓐ. Static variables are destroyed when the program exits.
ⓑ. Static variables are destroyed when the function where they are declared exits.
ⓒ. Static variables persist throughout the entire program execution.
ⓓ. Static variables are never destroyed.
Correct Answer: Static variables persist throughout the entire program execution.
Explanation: Static variables in C programming persist throughout the entire program execution. They are initialized once and retain their value between function calls.
87. What is the scope of a register variable in C programming?
ⓐ. Global to the file where it is declared.
ⓑ. Local to the function where it is declared.
ⓒ. Global to all functions within the file.
ⓓ. Global to the entire program.
Correct Answer: Local to the function where it is declared.
Explanation: Register variables in C programming have scope that is limited to the function where they are declared. They are not accessible outside of that function.
88. Which statement accurately describes the lifetime of a register variable in C?
ⓐ. Register variables are destroyed when the program exits.
ⓑ. Register variables are destroyed when the function where they are declared exits.
ⓒ. Register variables persist throughout the entire program execution.
ⓓ. Register variables are never destroyed.
Correct Answer: Register variables are destroyed when the function where they are declared exits.
Explanation: Register variables in C programming are destroyed (their memory is freed) when the function where they are declared exits. They do not persist beyond the function's execution.
89. In C programming, how can you extend the scope of a variable beyond a single function?
ⓐ. By declaring it as static.
ⓑ. By declaring it as register.
ⓒ. By declaring it as extern.
ⓓ. By declaring it as const.
Correct Answer: By declaring it as extern.
Explanation: In C programming, you can extend the scope of a variable beyond a single function by declaring it as `extern`, which allows it to be accessed across different files.
90. Which statement accurately describes the lifetime of a dynamically allocated variable in C?
ⓐ. Dynamically allocated variables are destroyed when the program exits.
ⓑ. Dynamically allocated variables are destroyed when the function where they are allocated exits.
ⓒ. Dynamically allocated variables persist throughout the entire program execution until explicitly deallocated.
ⓓ. Dynamically allocated variables are never destroyed.
Correct Answer: Dynamically allocated variables persist throughout the entire program execution until explicitly deallocated.
Explanation: Dynamically allocated variables in C programming persist throughout the entire program execution until they are explicitly deallocated using functions like `free()`.
91. Which storage class in C programming allocates memory dynamically during runtime?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: auto
Explanation: The `auto` storage class in C programming allocates memory dynamically during runtime and is used for local variables by default.
92. Which storage class in C programming stores variables in CPU registers for faster access?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: register
Explanation: The `register` storage class in C programming stores variables in CPU registers for faster access, optimizing performance.
93. Which storage class in C programming retains the value of a variable between function calls?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: static
Explanation: The `static` storage class in C programming retains the value of a variable between function calls, making it persistent throughout the program's execution.
94. Which storage class in C programming has external linkage by default?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: extern
Explanation: The `extern` storage class in C programming provides external linkage by default, allowing variables to be accessed across different files when properly declared.
95. Which storage class in C programming is typically used for declaring global variables?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: extern
Explanation: The `extern` storage class in C programming is typically used for declaring global variables, providing external linkage across multiple files.
96. Which statement is true regarding the initialization of static variables in C programming?
ⓐ. Static variables are automatically initialized to zero.
ⓑ. Static variables must be initialized at the point of declaration.
ⓒ. Static variables cannot be initialized with non-constant values.
ⓓ. Static variables are initialized with the value of the first command line argument.
Correct Answer: Static variables are automatically initialized to zero.
Explanation: Static variables in C programming are automatically initialized to zero if not explicitly initialized by the programmer.
97. In C programming, which storage class is used to declare variables with block scope?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: auto
Explanation: The `auto` storage class in C programming is used to declare variables with block scope, meaning they are accessible only within the block where they are declared.
98. Which storage class in C programming has the longest lifetime?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: extern
Explanation: The `extern` storage class in C programming has the longest lifetime because its variables are global and persist throughout the entire program execution.
99. Which storage class in C programming is used to optimize the access speed of variables?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: register
Explanation: The `register` storage class in C programming is used to optimize the access speed of variables by storing them in CPU registers instead of memory.
100. Which storage class in C programming is used for declaring variables that retain their value between function calls?
ⓐ. auto
ⓑ. register
ⓒ. static
ⓓ. extern
Correct Answer: static
Explanation: The `static` storage class in C programming is used for declaring variables that retain their value between function calls, making them persistent.