Computer Knowledge

Programming Fundamentals

2,381 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. Geekfunc();

  2. call Geekfunc();

  3. function Geekfunc();

  4. call function GeekFunc();

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

To call or invoke a function in JavaScript, you write the function's name followed by parentheses, which contain any arguments. For example, 'Geekfunc();' successfully executes the function.

Multiple choice
  1. interface

  2. throws

  3. short

  4. program

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

Words like 'interface', 'throws', and 'short' are reserved keywords in JavaScript (or reserved for future use, especially in strict mode). 'program' is not a reserved keyword and can be freely used as a variable or function name.

Multiple choice
  1. It is necessary for your program to run correctly.

  2. Helps you remember what a segment of code does.

  3. Comments are used to fix your code.

  4. Makes your code look pretty!

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

Comments are ignored by the compiler and do not affect how a program runs or fix errors. Instead, they serve as documentation to help programmers understand and remember what specific sections of code do.

Multiple choice
  1. //I am a comment

  2. class iAmaComment

  3. for (I am a Comment)

  4. int iAmaComment = (a < 0) ? -a : a;

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

In Java, double forward slashes (//) are used to denote a single-line comment. The other options represent class declarations, loop headers, or variable assignments.

Multiple choice
  1. Runtime error

  2. Logic error

  3. Syntax error

  4. Spelling error

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

A syntax error violates the grammar rules of the Java language, which prevents the compiler from translating the source code into bytecode. Because bytecode is not generated, the program cannot be run at all.

Multiple choice
  1. int to double

  2. int to String

  3. double to int

  4. double to String

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

Converting a double to an int is a narrowing conversion because it can result in a loss of precision as the fractional part is truncated. Therefore, Java requires an explicit cast, such as (int) myDouble, to confirm this conversion.

Multiple choice
  1. if (x > 2 or < 5)

  2. if (x = 4)

  3. if (x < 2 && x > 5)

  4. if (x)

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

In Java, conditional statements inside an if-statement must evaluate to a boolean value. Option C uses the valid logical AND operator (&&) to combine two valid boolean comparisons, even though the condition itself can never be true. Other options either use invalid syntax or try to use an integer as a boolean.

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. 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.