2.2.1 - Variables Expressions and Assignment.
1. What is a variable in C?
- a) A function used to perform operations
- b) A storage area with a name for data used in a program
- c) A reserved keyword
- d) A type of token
Correct Answer: b) A storage area with a name for data used in a program
2. Where should variables be declared in C?
- a) At the end of the program
- b) Inside loops only
- c) At the beginning of the main function or sub-functions
- d) In external files
Correct Answer: c) At the beginning of the main function or sub-functions
3. Which of the following is a valid C variable declaration?
- a) float x, y, z;
- b) int 1a, 2b, 3c;
- c) double a, b, c,;
- d) char name address;
Correct Answer: a) float x, y, z;
4. Which character must be used at the start of a variable name in C?
- a) Digit
- b) Letter or underscore
- c) Special character
- d) Space
Correct Answer: b) Letter or underscore
5. Which of the following is NOT a valid C data type?
- a) char
- b) w_char
- c) bool
- d) string
Correct Answer: d) string
6. What keyword is used to declare a static variable in C?
- a) static
- b) extern
- c) global
- d) local
Correct Answer: a) static
7. Which variable type in C is declared outside any function and can be used by any function?
- a) Local variable
- b) Static variable
- c) Global variable
- d) External variable
Correct Answer: c) Global variable
8. What keyword is used to declare a variable that can be shared across multiple source files in C?
- a) static
- b) global
- c) extern
- d) public
Correct Answer: c) extern
9. What are tokens in C programming?
- a) The smallest units that are significant to the compiler
- b) Types of variables
- c) Data storage units
- d) Reserved keywords
Correct Answer: a) The smallest units that are significant to the compiler
10. What is the purpose of the initializer in a variable declaration in C?
- a) To define the data type
- b) To specify the initial value of the variable
- c) To declare the variable's scope
- d) To assign the variable to a function
Correct Answer: b) To specify the initial value of the variable
11. Which of the following rules is NOT correct for naming variables in C?
- a) Variable names should not begin with digits
- b) Variable names can include spaces
- c) Variable names should not be predefined keywords
- d) Variables are usually declared in lowercase
Correct Answer: b) Variable names can include spaces
12. What type of variable in C retains its value between function calls?
- a) Local variable
- b) Static variable
- c) Global variable
- d) External variable
Correct Answer: b) Static variable
13. What is the correct way to declare a global variable in C?
- a) int global = 20;
- b) static int global = 20;
- c) extern int global;
- d) local int global = 20;
Correct Answer: a) int global = 20;
14. In C programming, what does the term ‘bus’ refer to?
- a) A software component that manages hardware
- b) A system that connects and facilitates data transfer between hardware components
- c) A type of data storage device
- d) An external peripheral device
Correct Answer: b) A system that connects and facilitates data transfer between hardware components
15. How many basic categories of software are there?
- a) One
- b) Two
- c) Three
- d) Four
Correct Answer: b) Two
2.2.2 - Constants, Keyword and Assignment.
16. Which of the following is used to declare a constant in C?
- A) define
- B) const
- C) constant
- D) static
Correct Answer: B) const
17. Which of the following is a valid string constant in C?
- A) "Hello World"
- B) 'H'
- C) 123
- D) 1.23
Correct Answer: A) "Hello World"
18. What is the correct syntax to define a symbolic constant?
- A) #const MAX 100
- B) const MAX = 100;
- C) #define MAX 100
- D) int MAX = 100;
Correct Answer: C) #define MAX 100
19. Which of the following is an invalid identifier in C?
- A) employee_name
- B) 123name
- C) _salary
- D) total_Amount
Correct Answer: B) 123name
20. How many characters can an identifier have in C?
- A) 63
- B) 31
- C) 100
- D) 255
Correct Answer: B) 31
21. Which of the following is NOT a valid keyword in C?
- A) int
- B) return
- C) string
- D) if
Correct Answer: C) string
22. Which special symbol is used to represent the null character in a string?
Correct Answer: A) \0
23. Which special character is used for function declaration and calls in C?
Correct Answer: C) ()
24. What does the special symbol * denote in C?
- A) It is used to denote a comment
- B) It is used as a pointer and multiplication operator
- C) It represents a constant
- D) It is used to include header files
Correct Answer: B) It is used as a pointer and multiplication operator
25. Which of the following is used to access members of a structure?
- A) . (Period)
- B) , (Comma)
- C) & (Ampersand)
- D) [] (Square hrackets)
Correct Answer: A) . (Period)
2.2.3 - Data Types.
26. Which of the following is the size of a char in C?
- A) 2 bytes
- B) 1 byte
- C) 4 bytes
- D) 8 bytes
Correct Answer: B) 1 byte
27. What is the range of an unsigned char in C?
- A) -128 to +127
- B) 0 to 255
- C) 0 to 65535
- D) -32768 to +32767
Correct Answer: B) 0 to 255
28. What is the default value of a signed char in C?
- A) -128 to +127
- B) 0 to 255
- C) 0 to 65535
- D) 0 to 4294967295
Correct Answer: A) -128 to +127
29. In a 16-bit environment, what is the range of an int in C?
- A) -2147483648 to +2147483647
- B) -32768 to +32767
- C) 0 to 65535
- D) 0 to 4294967295
Correct Answer: B) -32768 to +32767
30. Which of the following takes 4 bytes of memory and can store only positive values?
- A) int
- B) signed int
- C) unsigned int
- D) long int
Correct Answer: C) unsigned int
31. What is the format specifier for a long long int in C?
- A) %lld
- B) %d
- C) %u
- D) %lf
Correct Answer: A) %lld
32. Which of the following types in C does not take any space in memory?
- A) int
- B) void
- C) float
- D) char
Correct Answer: B) void
33. How many bytes does a double data type occupy in C?
- A) 2 bytes
- B) 4 bytes
- C) 8 bytes
- D) 10 bytes
Correct Answer: C) 8 bytes
34. Which of the following is a derived data type in C?
- A) int
- B) float
- C) array
- D) double
Correct Answer: C) array
35. What is the purpose of a pointer in C?
- A) To store a floating-point number
- B) To store the address of a variable
- C) To store a collection of elements of the same type
- D) To store multiple values in different data types
Correct Answer: B) To store the address of a variable
36. Which data type in C can store data of multiple different types?
- A) int
- B) struct
- C) union
- D) char
Correct Answer: B) struct
37. Which derived data type in C allows sharing memory among its members?
- A) array
- B) union
- C) struct
- D) function
Correct Answer: B) union
38. Which of the following is a double-precision floating-point value in C?
- A) float
- B) char
- C) double
- D) void
Correct Answer: C) double
39. What is the format specifier for a float value in C?
Correct Answer: C) %f
2.2.4 - Character and Lexical Statements.
40. In C programming, which character set is used to represent characters?
- A) Unicode
- B) ASCII
- C) UTF-8
- D) EBCDIC
Correct Answer: B) ASCII
41. How are characters represented in C code?
- A) Enclosed in double quotes
- B) Enclosed in single quotes
- C) Enclosed in parentheses
- D) Enclosed in curly hraces
Correct Answer: B) Enclosed in single quotes
42. What does the following C code represent?
char myChar = 'A';
- A) A string literal
- B) An integer value
- C) A character literal
- D) A floating-point literal
Correct Answer: C) A character literal
43. What is the role of lexical analysis in programming languages?
- A) To execute the program
- B) To hreak down source code into tokens
- C) To compile the program
- D) To optimize the code
Correct Answer: B) To hreak down source code into tokens
44. Which of the following is NOT a lexical unit (token) in C?
- A) Keyword
- B) Identifier
- C) Memory address
- D) Operator
Correct Answer: C) Memory address
45. In the C statement int sum = num1 + num2;, what is + considered as?
- A) Keyword
- B) Identifier
- C) Operator
- D) Literal
Correct Answer: C) Operator
46. Which of the following correctly identifies the statement terminator in C?
Correct Answer: C) ;
47. In C programming, what does the term "token" refer to?
- A) The largest building block of the code
- B) The smallest meaningful unit in a program
- C) A type of comment in the code
- D) The execution step in the code
Correct Answer: B) The smallest meaningful unit in a program
48. In C, which of the following is an example of a keyword?
- A) sum
- B) int
- C) num1
- D) myChar
Correct Answer: B) int
49. In the following statement: int num1;, what is num1 classified as?
- A) Keyword
- B) Identifier
- C) Operator
- D) Literal
Correct Answer: B) Identifier
2.2.5 - Define and Include.
50. What is the purpose of the #define directive in C programs?
- A) To include header files
- B) To define macros
- C) To declare variables
- D) To execute loops
Correct Answer: B) To define macros
51. Where are preprocessor directives like #define and #include typically written in a C program?
- A) Inside the main() function
- B) At the end of the program
- C) Outside the main() function, at the top
- D) Inside user-defined functions
Correct Answer: C) Outside the main() function, at the top
52. What is another name for the #define directive?
- A) Variable declaration directive
- B) Macro directive
- C) Function declaration directive
- D) Looping directive
Correct Answer: B) Macro directive
53. How does the #define directive work in a C program?
- A) It substitutes the macro name with a variable
- B) It substitutes the macro name with a constant or expression
- C) It substitutes variables with their values
- D) It compiles the program
Correct Answer: B) It substitutes the macro name with a constant or expression
54. What is the purpose of the #include directive in C programs?
- A) To define constants
- B) To include files
- C) To declare variables
- D) To execute loops
Correct Answer: B) To include files
55. What is another name for the #include directive?
- A) Looping directive
- B) File inclusion directive
- C) Variable declaration directive
- D) Function definition directive
Correct Answer: B) File inclusion directive
56. What type of files does the #include directive insert into the C program?
- A) Text files
- B) Header files containing definitions for pre-defined functions
- C) Data files
- D) Configuration files
Correct Answer: B) Header files containing definitions for pre-defined functions
57. Which of the following is a pre-defined function found in header files included using the #include directive?
- A) for()
- B) printf()
- C) int main()
- D) while()
Correct Answer: B) printf()
58. What happens when the #include directive is used in a C program?
- A) The header file is ignored
- B) The content/code from the specified header file is inserted into the program before compiling
- C) The main() function is executed
- D) A new function is defined
Correct Answer: B) The content/code from the specified header file is inserted into the program before compiling
59. Which directive is used to declare constant values or named expressions in C programs?
- A) #include
- B) #define
- C) #macro
- D) #const
Correct Answer: B) #define
2.2.6 - Conditional Compilation.
60. Which directive is the reverse of #ifdef in conditional compilation?
- A) #endif
- B) #if
- C) #ifndef
- D) #elif
Correct Answer: C) #ifndef
61. What happens when the condition in a #if directive evaluates to a non-zero value?
- A) The block following #endif is executed
- B) The block following #if is executed
- C) The program halts compilation
- D) The condition is ignored
Correct Answer: B) The block following #if is executed
62. Which directive allows us to control the filename and line number reported in compilation errors?
- A) #line
- B) #elif
- C) #ifdef
- D) #error
Correct Answer: A) #line
63. What is the purpose of the #error directive?
- A) To suppress all warnings during compilation
- B) To define macros conditionally
- C) To terminate the compilation process and display an optional error message
- D) To specify an alternative file for error reporting
Correct Answer: C) To terminate the compilation process and display an optional error message
64. Which directive is used to specify an alternative block of statements if the condition in #if is false and another condition is also false?
- A) #endif
- B) #elif
- C) #else
- D) #ifdef
Correct Answer: B) #elif
65. In the directive #line 100 "myfile.c", what is the significance of 100?
- A) It sets the error message to 100
- B) It defines the starting line number for subsequent lines
- C) It changes the file's name to "myfile.c"
- D) It ends conditional compilation
Correct Answer: B) It defines the starting line number for subsequent lines
66. What happens if the condition in a #elif directive evaluates to zero?
- A) The statements after #elif are executed
- B) The statements in the next #else or #endif are executed
- C) The entire program stops execution
- D) The program ignores all further conditions
Correct Answer: B) The statements in the next #else or #endif are executed
67. Which directive allows the execution of a block of statements if the macro is not defined?
- A) #if
- B) #endif
- C) #ifndef
- D) #else
Correct Answer: C) #ifndef
68. What must follow every #ifdef or #ifndef directive?
- A) #line
- B) #else
- C) #endif
- D) #error
Correct Answer: C) #endif
69. What is required when using the #error directive?
- A) A filename
- B) An optional error message
- C) A line number
- D) A condition
Correct Answer: B) An optional error message