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 6 of 10

  • A. a = 11, b = 4, result = 3
  • B. a = 10, b = 4, result = 2
  • C. a = 11, b = 4, result = 2
  • D. Undefined behavior

Explanation: • --b: Pre-decrement, so b becomes 4.• a++: Post-increment, so 10 is used in the division, and then a becomes 11.• 10 / 4 = 2

Correct answer: a = 11, b = 4, result = 2
  • A. x = 3, y = 13
  • B. x = 5, y = 17
  • C. x = 4, y = 14
  • D. x = 4, y = 17

Explanation: 2 * x++: Uses the current value of x (2), then increments x to 3 -> Result: 43 * ++x: Increments x to 4, then uses the new value (4) -> Result: 124 + 12 = 16

Correct answer: x = 4, y = 17
  • A. USHRT_MAX + 1
  • B. USHRT_MAX + 2
  • C. 0
  • D. 1

Explanation: • USHRT_MAX represents the maximum value an unsigned short int can hold.• Adding to an unsigned integer at its maximum value causes a wrap-around to zero

Correct answer: 0
  • A. 128
  • B. -128
  • C. 0
  • D. A compiler warning or error

Explanation: The char type is usually signed, with a range of -128 to 127.Assigning 128 to a signed char causes an overflow, wrapping around to the minimum representable value

Correct answer: -128
  • A. x = 1, y = 3, z = 0
  • B. x = 1, y = 3, z = 1
  • C. x = 2, y = 3, z = 1
  • D. x = 2, y = 4, z = 0

Explanation: • x-- decrements x to 1, but returns the original value (2), which is non-zero (true).• --y decrements y to 3. Since the first part of the && expression was true, the second part is also evaluated.• z is assigned 1 (true).

Correct answer: x = 1, y = 3, z = 1
  • A. a = 9, b = -6, x = 15
  • B. a = 10, b = -5, x = 15
  • C. a = 9, b = -6, x = 14
  • D. a = 9, b = -5, x = 14

Explanation: • --a: Decrements a to 9.• b--: Uses the current value of b (-5) in the subtraction and then decrements b to -6.• 9 - (-5) = 14

Correct answer: a = 9, b = -6, x = 14
  • A. 10 9 8 7 6 5 4 3 2 1 0
  • B. 10 9 8 7 6 3 2 1 0
  • C. 10 9 8 7 6 4 3 2 1 0
  • D. 10 9 8 7 6 5 3 2 1 0

Explanation: 1. The loop runs while x is non-zero.2. When x becomes 5, x-= 2 changes it to 3. This skips the next iteration due to the post-decrement in the while condition

Correct answer: 10 9 8 7 6 3 2 1 0
  • A. x = 10, y = -50
  • B. x = 9, y = -50
  • C. x = 10, y = -45
  • D. x = 9, y = -45

Explanation: The post-decrement in x-- means the original value of x (10) is used in the multiplication, and then x is decremented to 9

Correct answer: x = 9, y = -50
  • A. Procedure
  • B. Identifier
  • C. Operator
  • D. Macros

Explanation: Macro is a piece of code that is replaced with another piece of code before the program is compiled or run. Macros are not the same as identifiers, although macros can sometimes be used to define identifiers.

Correct answer: Identifier
  • A. 3
  • B. 2
  • C. 4
  • D. 5

Explanation: The correct option is (c), 4.There are two main types of identifiers in programming languages:Internal identifiers: These are identifiers that are declared within a function or block of code and have local scope. They are only visible and accessible within the function or block where they are declared.External identifiers: These are identifiers that are declared outside any function or block of code and have global scope. They are visible and accessible to all functions within the same file.

Correct answer: 4
  • A. User defined identifier
  • B. Function identifier
  • C. Standard identifier
  • D. Polymorphism

Explanation: These are special words that have predefined meanings in the C language. They cannot be used as user-defined identifiers. Examples of standard identifiers include int, float, for, while, and if. In conclusion, standard identifiers are the identifiers that have special meaning in the C language. These keywords are reserved words that have specific purposes within the language and cannot be used for other purposes.

Correct answer: Standard identifier
  • A. User defined identifier
  • B. Standard identifier
  • C. Programmer identifier
  • D. Both (a) and (b)

Explanation: User defined identifier refers to a name created by the programmer to identify specific elements within their program. These names are not predefined and can vary depending on the programmer's preference. While printf and scanf are user-defined identifiers in the C programming language, they are not considered standard identifiers because their usage is specific to C and not applicable across different systems or languages.

Correct answer: Standard identifier
  • A. Programmer identifier
  • B. Standard identifiers
  • C. User defined identifier
  • D. All of these

Explanation: In programming, programmers define identifiers (names) to store data. These identifiers are not pre-defined by the programming language itself (standard identifiers) but rather created by the programmer specifically for their program

Correct answer: User defined identifier
  • A. Comments
  • B. Identifier
  • C. Variable
  • D. Data type

Explanation: A data type defines a set of values and the operations that can be performed on those values. For example, the integer data type defines a set of whole numbers and operations such as addition, subtraction, multiplication, and division.In conclusion, a data type is the only option that defines both a set of values and a set of operations on those values. Data types provide a way to organize data and ensure that it is used correctly in a program.

Correct answer: Data type
  • A. long
  • B. Preengeering.pk
  • C. do
  • D. 9.2

Explanation: The correct option is (d), 9.2. A floating-point number is a number that can represent a wide range of values, including numbers with decimals. It stores the number using a combination of two parts:Significand (mantissa): The digits of the number.Exponent: The base (usually 2) raised to a power that determines the position of the decimal point.In the options provided, only 9.2 has a decimal point, making it a floating-point number.

Correct answer: 9.2
  • A. 8
  • B. 4
  • C. 2
  • D. 16

Explanation: In conclusion, the double data type typically takes 8 bytes of memory in most computer systems. This allows it to store a wider range of values and achieve more precision compared to data types like float.

Correct answer: 8
  • A. Cancellation error
  • B. Arithmetic underflow
  • C. Arithmetic overflow
  • D. Logical Error

Explanation: The correct answer is: (b) Arithmetic underflow.Arithmetic underflow occurs in computer arithmetic when the result of an operation is too small to be represented accurately within the given number of bits. In simpler terms, when two very small numbers are multiplied, the result can be a number that is too small for the computer to represent accurately, so it becomes zero.

Correct answer: Arithmetic underflow
  • A. Reserved words
  • B. Keywords
  • C. Programming words
  • D. Both (a) and (b)

Explanation: The correct answer is (d) Both (a) and (b).(a) Keywords and (b) Reserved words are different terms for the same concept in C programming. These are special words that have fixed meanings and cannot be used for other purposes in your program. For example, int, float, for, while, and if are all keywords (or reserved words).In conclusion, both keywords and reserved words refer to the same concept in C programming, and they are the correct answer to the question. These predefined words have specific meanings and functionalities within the language.

Correct answer: Both (a) and (b)
  • A. Value
  • B. Name
  • C. Data type
  • D. Both (b) and (c)

Explanation: The correct answer is (d) Both (a) and (b).(a) Keywords and (b) Reserved words are different terms for the same concept in C programming. These are special words that have fixed meanings and cannot be used for other purposes in your program. For example, int, float, for, while, and if are all keywords (or reserved words).In conclusion, both keywords and reserved words refer to the same concept in C programming, and they are the correct answer to the question. These predefined words have specific meanings and functionalities within the language.

Correct answer: Both (b) and (c)
  • A. Operator
  • B. Constant
  • C. Comments
  • D. Variable

Explanation: The correct option is (d), Variable.A variable is a named storage location that can hold a value during program execution. The value stored in a variable can change throughout the program as needed. This is what makes variables essential for performing calculations, storing user input, and keeping track of data within a program.

Correct answer: Variable