Free Programming Basics MCQs with Answers
183 Programming Basics MCQs from Computer Science and IT, each with the correct answer and a written explanation of why it is correct. Free and unlimited, with no account needed.
Programming basics covers algorithms, flowcharts, pseudocode, variables, constants, data types, operators, input and output, conditional statements and loops. It also introduces functions, arrays, strings, debugging and common programming errors, with attention to the difference between syntax errors, runtime errors and logical errors in a program.
Last updated
183 questions · page 4 of 10
- A. number
- B. Lower case character
- C. Underscore (_)
- D. Upper case character
Explanation: In most programming languages, variable names cannot start with a number. This is because variable names are used to identify and refer to data in the program, and numbers are already used for numerical values. Starting a variable name with a number would create confusion between variable names and numeric constants
Correct answer: number- A. * (asterisk)
- B. = (assignment)
- C. && (logical AND)
- D. , (comma)
Explanation: In C programming, the comma (,) operator has the lowest precedence level. This means that when multiple comma-separated expressions appear in a statement, they are evaluated from left to right. Precedence level refers to the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated first. For example, in the expression 2 * 3 + 4, the multiplication is performed first (because * has higher precedence than +) and then the addition is performed
Correct answer: , (comma)- A. 2
- B. 4
- C. 8
- D. 16
Explanation: In most modern computer systems, a double data type takes 8 bytes of memory. This is because the double data type is designed to store double-precision floating-point numbers, which offer a higher degree of precision than single-precision floating-point numbers (typically stored in 4 bytes). The additional precision of double-precision numbers comes at the cost of using more memory
Correct answer: 8- A. Float
- B. Long int
- C. Long double
- D. Unsigned long int
Explanation: An unsigned long int is similar to a long int but can only store non-negative integer values. It also does not offer high precision for real numbersPrecision refers to the number of significant digits that can be represented by a data type. Higher precision allows for more accurate representation of real numbersIn summary:For high precision real number representation, use long double.For moderate precision and single-precision floating-point representation, use float.For integer values, use long int or unsigned long int depending on the signed or unsigned nature of the data
Correct answer: Unsigned long int- A. Operators
- B. Operands
- C. Comments
- D. Both (a) & (b)
Explanation: An expression in programming is a combination of values (operands) and instructions on how to manipulate those values (operators).Operands are the data values that the operators act on. They can be numbers, variables, constants, or even the results of other expressions.Operators are symbols that specify how the operands should be combined or manipulated. Common operators include arithmetic operators (like +, -, *, /), comparison operators (like ==, !=, <, >), logical operators (like &&, ||, !), and assignment operators (=).In order to create a meaningful expression, you need to combine both operands and operators. For instance, the expression 2 + 3 includes the operands 2 and 3 and the operator +. The expression evaluates to 5
Correct answer: Both (a) & (b)- A. Variable
- B. Identifier
- C. Operator
- D. Constant
Explanation: A constant is a data item in a program whose value cannot be changed after it is assigned. It represents a fixed value throughout the program's execution. Constants are useful for defining known values that don't change, such as mathematical constants (e.g., pi), conversion factors, or program configuration settings
Correct answer: Constant- A. Constant
- B. Variable
- C. Address
- D. Data type
Explanation: A variable is a named memory location that stores data that can change during program execution. The value stored in a variable can be modified by assignment statements or through calculations within the program. Variables are essential for storing and manipulating data throughout the program's logic
Correct answer: Variable- A. int, float, char
- B. void, return
- C. printf, scanf
- D. #include, #define
Explanation: In C programming, user-defined functions are created using a function header that includes the following elements:1. Return type: The return type specifies the data type of the value that the function will return. Common data types used for return types include int (integer), float (floating-point number), char (character), and void (meaning the function does not return a value).2. Function name: This is a unique identifier that you choose to name your function. It should be descriptive and reflect the function's purpose.3. Parameter list (optional): This list includes the parameters (arguments) that the function can accept. Parameters are variables that are used to pass data into the function. Each parameter has a data type and an optional name.Here's an example of a user-defined function in C:Cint add(int x, int y) { // function body return x + y;}In this example:• int is the return type, specifying the function will return an integer value.• add is the function name.• int x, int y is the parameter list, where x and y are integer parameters
Correct answer: int, float, char- A. '6'
- B. "hello"
- C. 345
- D. 3.14159
Explanation: A character constant is a single character enclosed in single quotation marks ('). It is used to represent a single character value, such as a letter, number, or symbol. In this case, '6' is a character constant that represents the numeral '6'
Correct answer: '6'- A. Cancellation error
- B. Arithmetic underflow
- C. Arithmetic overflow
- D. Implicit casting
Explanation: Arithmetic underflow occurs when the result of a mathematical operation is too small to be represented accurately in the computer's memory. In the case of multiplying two small numbers, if the product is very close to zero, it might be rounded down to zero due to the limitations of the number representation system used by the computer In conclusion, when two small numbers are multiplied and the result is zero, this is most likely due to arithmetic underflow, where the product is too small to be accurately represented in memory
Correct answer: Arithmetic underflow- A. Significand
- B. Mantissa
- C. Exponent
- D. Precision
Explanation: In the decimal number system, the number of digits to the right of the decimal point is called precision. It refers to the level of detail or exactness in the representation of a real number. A higher number of digits to the right of the decimal point indicates higher precision
Correct answer: Precision- A. int number = 0;
- B. number int = 0;
- C. int 0number;
- D. None of these
Explanation: In C, the correct way to declare a variable involves specifying the data type, followed by the variable name, and optionally an initial value using an assignment operator (=).• Data type: This specifies the kind of data the variable can hold, such as integers (int), floating-point numbers (float), characters (char), etc.• Variable name: This is a name chosen by the programmer to identify the variable. It should follow naming conventions (letters, digits, and underscores, starting with a letter).• Assignment (optional): You can initialize the variable with a value during declaration using the assignment operator (=).
Correct answer: int number = 0;- A. 1 Character
- B. 2 Character
- C. 6 Character
- D. 4 Character
Explanation: In C programming, a character constant is a single character enclosed in single quotation marks ('). It represents a literal character value and can be any character in the character set, including letters, numbers, symbols, and punctuation marks.Here are some examples of valid character constants:• 'a'• '5'• '$'• '&'
Correct answer: 1 Character- A. 16
- B. 31
- C. 63
- D. Depends on the compiler
Explanation: According to the ANSI C standard (C89 and later versions), an identifier (variable name) can have a maximum of 31 significant characters. This means that the first 31 characters of the identifier are considered in naming, and any characters beyond that are ignored by the compiler. According to the ANSI C standard (C89 and later versions), an identifier (variable name) can have a maximum of 31 significant characters. This means that the first 31 characters of the identifier are considered in naming, and any characters beyond that are ignored by the compiler.
Correct answer: 31- A. Single line comments
- B. Multiline comments
- C. Single line sentence
- D. Multiline commands
Explanation: In C programming, text enclosed between /* and */ represents multiline comments. These comments are ignored by the compiler and do not affect the program's execution. They are used to enhance code readability by providing explanations, annotations, or descriptions of code sections. Multiline comments can span across multiple lines, providing more space for detailed explanations compared to single-line comments
Correct answer: Multiline comments- A. struct
- B. union
- C. enum
- D. typedef
Explanation: struct is the keyword used to define a user-defined data type called a structure in C programming. A structure allows you to group together variables of different data types under a single name, creating a more complex data type Here's an example of a structure definition in C:Cstruct Point { int x; float y;};In this example, struct Point defines a structure named Point that has two members: x of type integer and y of type float. You can then declare variables of this structure type to store data points
Correct answer: struct- A. Every variable must be declared before it is used
- B. C code needs to be compiled before execution
- C. C has a rich set of data types
- D. Type conversions require explicit casting
Explanation: • Strongly typed languages enforce strict type checking. This means that the data type of a variable is associated with it at the time of declaration, and any operations or assignments involving the variable must adhere to its data type.In C programming:• Type conversions are operations that change the data type of a value.• Explicit casting is the process of manually instructing the compiler to convert a value from one data type to another. This is done using casting operators like (int), (float), etc.The requirement for explicit casting in C is a strong indicator of its strict type checking nature. The compiler enforces type safety by requiring the programmer to explicitly declare any data type conversions, helping to prevent potential errors caused by unintended type mismatches
Correct answer: Type conversions require explicit casting- A. RAM
- B. ROM
- C. Hard disk
- D. Cache
Explanation: RAM (Random Access Memory) is a volatile memory, meaning that it loses its data when the computer is turned off or loses power. RAM is used to store the operating system, programs, and data that are currently being used by the CPU. When the computer is turned off, the electrical charge that keeps the data in RAM is lost, and the data is erased
Correct answer: RAM- A. void
- B. int
- C. main
- D. function
Explanation: In C programming, the void keyword is used to declare a function that does not return any value. When a function is declared as void, it means that the function may or may not perform operations but it does not explicitly return a value to the caller using a return statement
Correct answer: void- A. This is a double quote: "
- B. This is a double quote: \
- C. This is a double quote:
- D. A compiler error
Explanation: \" is the escape sequence used to include a double quotation mark within a string literal.
Correct answer: This is a double quote: "