Computer Knowledge

Programming Fundamentals

2,611 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice
  1. true

  2. 1

  3. null

  4. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, boolean variables can only hold the literal values 'true' or 'false' (all lowercase). Unlike some other languages, Java does not allow assigning integers like 1 or capitalized words like 'False' to a boolean variable.

Multiple choice
  1. boolean

  2. String

  3. int

  4. double

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, primitive data types include byte, short, int, long, float, double, char, and boolean. 'String' is a class (a reference type) rather than a primitive data type, as it represents a sequence of characters and has its own methods.

Multiple choice
  1. to give additional informition

  2. to omit information

  3. to show sarcasm

  4. to show intent

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Parentheses and brackets are punctuation marks used to enclose additional, explanatory, or clarifying information that is not essential to the main sentence structure. Although Option A contains a minor typo ("informition"), it correctly identifies this primary function.

Multiple choice
  1. contain at least 3 numbers

  2. USE ALL UPPER CASE LETTERS

  3. give a sense of what is contained in it

  4. link to a function name

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Variable names should be descriptive and meaningful so that anyone reading the code can easily understand what data the variable holds. Using arbitrary numbers or all uppercase letters is not a standard requirement, and linking to a function name is not necessary for variable declaration.

Multiple choice
  1. The CPU from completing any more cycles

  2. the further execution of code

  3. The internet from being accessed

  4. Memory being accessed

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A runtime error occurs while a program is running, often due to unexpected inputs or operations like dividing by zero. When this happens, the program typically crashes or halts, which prevents the further execution of its code.

Multiple choice
  1. IF statement

  2. For loop

  3. While loop

  4. List

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

An 'IF' statement is a conditional control structure used in programming to execute different blocks of code based on whether a condition is true or false. Loops (like For and While) are used for repetition, and lists are data structures used to store multiple items.

Multiple choice
  1. Uses a value to return the key

  2. Uses a value to return a value

  3. Uses a key to return a value

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The get() method in Python dictionaries is used to retrieve the value associated with a specified key. If the key does not exist in the dictionary, it returns None (or a specified default value) instead of raising an error.

Multiple choice
  1. A datatype

  2. A bus

  3. An error

  4. A constant

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A Boolean is a fundamental data type in computer science that can only hold one of two values: True or False. It is used extensively in programming for conditional statements and logical operations.

Multiple choice
  1. variable carName;

  2. v carName;

  3. var carName;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In JavaScript, variables are declared using the 'var', 'let', or 'const' keywords. 'var' is the traditional method.

Multiple choice
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript and Java are two completely different programming languages with different syntax and use cases.

Multiple choice
  1. while (i <= 10)

  2. while (i <= 10; i++)

  3. while i = 1 to 10

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A while loop only requires a condition in parentheses to execute as long as that condition is true.

Multiple choice
  1. call function myFunction()

  2. myFunction()

  3. call myFunction()

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To call a function in JavaScript, you use its name followed by parentheses, which may contain arguments.

Multiple choice

In the context of computer programming, what is the purpose of a loop?

  1. Repeating a block of code multiple times

  2. Storing data in memory

  3. Performing calculations

  4. Displaying output

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A loop is a programming construct that allows a block of code to be executed repeatedly until a certain condition is met. It is used to perform repetitive tasks and iterate through data structures.

Multiple choice

In Dynamic Logic, what is the purpose of the diamond operator &lt;&gt;?

  1. It denotes the possibility of a program execution.

  2. It denotes the necessity of a program execution.

  3. It denotes the weakest precondition of a program.

  4. It denotes the strongest postcondition of a program.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The diamond operator &lt;&gt; in Dynamic Logic represents the possibility of a program execution. It is used to express statements that are true in at least one possible execution of the program.