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 technology programming languages
  1. 1 This is the pseudocode representing the two types of assert statements:

  2. 2 Always handle an AssertionError in a try-catch-finally block.

  3. 3 This is the pseudocode representing the two types of assert statements:

  4. 4 Assertions of the 'assert booleanExpression;' variety should not be disabled before distributing the software.

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice technology programming languages
    1. The quotes should not be around false.
    1. New should be after Boolean.
    1. A boolean is expected not a Boolean.
    1. The Semi-colon should not be used.
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, you cannot use a Boolean wrapper object directly in an if statement - the condition expects a primitive boolean. The Boolean object must be unboxed (either explicitly via booleanValue() or through auto-unboxing in some contexts). The code fails because 'if (b)' attempts to use the Boolean object as a boolean primitive.

Multiple choice technology mainframe
  1. send map() cursor()

  2. cursor()

  3. send ()

  4. none of the above

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

To position the cursor statically in a CICS program, use 'SEND MAP() CURSOR()'. This command sends the map to the display and positions the cursor at a specific field. The CURSOR() option specifies where the cursor should be placed. Option B (cursor() alone) is incomplete syntax, and Option C (send()) lacks both the map and cursor specifications.

Multiple choice technology operating systems
  1. 1 True

  2. 2 False

  3. 3

  4. 4

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

A zombie process is a terminated process whose entry remains in the process table. If the parent dies without reaping the child, the child is adopted by 'init' (PID 1), which then reaps it, but the zombie state itself refers to the period before reaping.

Multiple choice technology operating systems
  1. 1 getenv(), setenv()

  2. 2 getenv(), putenv()

  3. 3 readenv(), writeenv()

  4. 4 You cannot environmement variables inside a program

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

getenv() retrieves the value of an environment variable, and putenv() changes or adds an environment variable to the current environment. setenv() is not part of standard C (though it exists as a BSD/gnu extension), and readenv()/writeenv() do not exist.

Multiple choice technology programming languages
  1. a. String str[];

  2. b. String str[5] = new String[5];

  3. c. String str[] = new String[] {"string1", "string2", "string3", "string4", "string5

  4. d. String str[] = {"string1","string2", "string3", "string4", "string5"};

Reveal answer Fill a bubble to check yourself
A,C,D Correct answer
Explanation

Option A is a valid declaration. Option C and D are valid initializations. Option B is invalid because you cannot specify the array dimension on the left side of the assignment in Java.

Multiple choice technology
  1. Compilation error

  2. You are well versed!

  3. versed!

  4. You are well

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

The Perl print statement outputs the string "You are well versed!" followed by a newline character "\n". The semicolon terminates the statement. Perl's print function simply outputs the given string to STDOUT. Options C and D would only be true if we were using substring operations or different string splitting functions.

Multiple choice technology
  1. True

  2. cap

  3. able

  4. compilation error

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

The regex match operator =~ in Perl returns true if the pattern matches the string. The pattern /able/ is found in "Capable", so the match succeeds and returns true (which evaluates to 1 in boolean context). Option B 'cap' is not the return value, option C 'able' is just the matched substring, and option D is incorrect because this is valid Perl syntax.

Multiple choice technology security
  1. Replace cin call in line 3 with gets() function

  2. The length of input from cin cannot be limited. Use a larger array for fname

  3. Use cin.width[20] before line 3

  4. Use cin.size[19] before line 3

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

The 'cin >>' operator is unbounded and can cause buffer overflows. Using 'cin.width(n)' or the 'setw(n)' manipulator limits the number of characters read into the buffer, ensuring it does not exceed the array size.

Multiple choice technology security
  1. No vulnerabilities are present

  2. Line 1 should only use malloc(inputsize)

  3. Line 2 should be for (i=0; i<=n, i++)

  4. Line 1 should use calloc() instead of malloc()

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

The code uses uninitialized memory from malloc(). Using += on uninitialized values reads garbage values. calloc() zero-initializes memory, which is the safe approach. Option B would allocate insufficient space, option C would cause an out-of-bounds access, and option A is incorrect - there is a vulnerability.

Multiple choice technology databases
  1. Exception

  2. Executable

  3. Declarative

  4. Anonymous

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

The Executable section of a PL/SQL block contains the procedural code and starts with the BEGIN keyword. The Exception section (EXCEPTION) handles errors, the Declarative section (DECLARE) defines variables and types, and Anonymous is not a section name but a block type.