2.2 - C Statement.


Back Button Home

2.2.1 - Variables Expressions and Assignment.


1. What is a variable in C?
Correct Answer: b) A storage area with a name for data used in a program
2. Where should variables be declared in C?
Correct Answer: c) At the beginning of the main function or sub-functions
3. Which of the following is a valid C variable declaration?
Correct Answer: a) float x, y, z;
4. Which character must be used at the start of a variable name in C?
Correct Answer: b) Letter or underscore
5. Which of the following is NOT a valid C data type?
Correct Answer: d) string
6. What keyword is used to declare a static variable in C?
Correct Answer: a) static
7. Which variable type in C is declared outside any function and can be used by any function?
Correct Answer: c) Global variable
8. What keyword is used to declare a variable that can be shared across multiple source files in C?
Correct Answer: c) extern
9. What are tokens in C programming?
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?
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?
Correct Answer: b) Variable names can include spaces
12. What type of variable in C retains its value between function calls?
Correct Answer: b) Static variable
13. What is the correct way to declare a global variable in C?
Correct Answer: a) int global = 20;
14. In C programming, what does the term ‘bus’ refer to?
Correct Answer: b) A system that connects and facilitates data transfer between hardware components
15. How many basic categories of software are there?
Correct Answer: b) Two

2.2.2 - Constants, Keyword and Assignment.


16. Which of the following is used to declare a constant in C?
Correct Answer: B) const
17. Which of the following is a valid string constant in C?
Correct Answer: A) "Hello World"
18. What is the correct syntax to define a symbolic constant?
Correct Answer: C) #define MAX 100
19. Which of the following is an invalid identifier in C?
Correct Answer: B) 123name
20. How many characters can an identifier have in C?
Correct Answer: B) 31
21. Which of the following is NOT a valid keyword in C?
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?
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?
Correct Answer: A) . (Period)

2.2.3 - Data Types.


26. Which of the following is the size of a char in C?
Correct Answer: B) 1 byte
27. What is the range of an unsigned char in C?
Correct Answer: B) 0 to 255
28. What is the default value of a signed char in C?
Correct Answer: A) -128 to +127
29. In a 16-bit environment, what is the range of an int in C?
Correct Answer: B) -32768 to +32767
30. Which of the following takes 4 bytes of memory and can store only positive values?
Correct Answer: C) unsigned int
31. What is the format specifier for a long long int in C?
Correct Answer: A) %lld
32. Which of the following types in C does not take any space in memory?
Correct Answer: B) void
33. How many bytes does a double data type occupy in C?
Correct Answer: C) 8 bytes
34. Which of the following is a derived data type in C?
Correct Answer: C) array
35. What is the purpose of a pointer in C?
Correct Answer: B) To store the address of a variable
36. Which data type in C can store data of multiple different types?
Correct Answer: B) struct
37. Which derived data type in C allows sharing memory among its members?
Correct Answer: B) union
38. Which of the following is a double-precision floating-point value in C?
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?
Correct Answer: B) ASCII
41. How are characters represented in C code?
Correct Answer: B) Enclosed in single quotes
42. What does the following C code represent?
char myChar = 'A';
Correct Answer: C) A character literal
43. What is the role of lexical analysis in programming languages?
Correct Answer: B) To break down source code into tokens
44. Which of the following is NOT a lexical unit (token) in C?
Correct Answer: C) Memory address
45. In the C statement int sum = num1 + num2;, what is + considered as?
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?
Correct Answer: B) The smallest meaningful unit in a program
48. In C, which of the following is an example of a keyword?
Correct Answer: B) int
49. In the following statement: int num1;, what is num1 classified as?
Correct Answer: B) Identifier

2.2.5 - Define and Include.


50. What is the purpose of the #define directive in C programs?
Correct Answer: B) To define macros
51. Where are preprocessor directives like #define and #include typically written in a C program?
Correct Answer: C) Outside the main() function, at the top
52. What is another name for the #define directive?
Correct Answer: B) Macro directive
53. How does the #define directive work in a C 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?
Correct Answer: B) To include files
55. What is another name for the #include directive?
Correct Answer: B) File inclusion directive
56. What type of files does the #include directive insert into the C program?
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?
Correct Answer: B) printf()
58. What happens when the #include directive is used in a C program?
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?
Correct Answer: B) #define

2.2.6 - Conditional Compilation.


60. Which directive is the reverse of #ifdef in conditional compilation?
Correct Answer: C) #ifndef
61. What happens when the condition in a #if directive evaluates to a non-zero value?
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?
Correct Answer: A) #line
63. What is the purpose of the #error directive?
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?
Correct Answer: B) #elif
65. In the directive #line 100 "myfile.c", what is the significance of 100?
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?
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?
Correct Answer: C) #ifndef
68. What must follow every #ifdef or #ifndef directive?
Correct Answer: C) #endif
69. What is required when using the #error directive?
Correct Answer: B) An optional error message