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 technology mainframe
  1. Run if return codes from any previous step(s) were equal to zero. Skip this step if the return code from any previous steps are not equal to zero (0,NE).

  2. Run if return codes from any previous step(s) were not equal to zero. Skip this step if the return code from any previous steps are equal to zero (0,NE).

  3. Run if return codes from any previous step(s) were equal to zero. Run this step if the return code from any previous steps are not equal to zero (0,NE).

  4. Run if return codes from any previous step(s) were not equal to zero. Run this step if the return code from any previous steps are not equal to zero (0,NE).

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

In JCL, the COND parameter specifies conditions for skipping a step. COND=(0,NE) means 'if 0 is not equal to the return code of any previous step, skip this step'. Therefore, the step runs only if 0 is equal to the return code of all previous steps (i.e. return codes were 0).

Multiple choice technology databases
  1. procedure

  2. trigger

  3. function

  4. all

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

Functions are specifically designed to return values in PL/SQL. Procedures perform actions but don't return values directly (they can use OUT parameters). Triggers are event-driven and execute implicitly when an event occurs - they don't return values.

Multiple choice technology security
  1. Forcing buffer overflows

  2. Submitting random long strings to the application

  3. Causing underflow problems

  4. Including string specifiers in input data

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

Format string vulnerabilities occur when user input is passed directly as the format string argument to functions like printf. By including format specifiers like %x, %s, or %n in the input data, attackers can read memory contents or write to arbitrary memory addresses. Testing for these vulnerabilities involves submitting inputs containing format specifiers to see if the application interprets them as format commands rather than literal text.

Multiple choice technology security
  1. Registry settings

  2. The library search order

  3. Buffer overflows

  4. Library input validation flaws

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

DLL hijacking exploits Windows search order to load a malicious DLL from a directory checked before the system directory. Registry settings, buffer overflows, and input validation are not search-order exploits.

Multiple choice technology security
  1. Binary Fault Injection

  2. Property-based Testing

  3. Source code fault injection

  4. Black Box Debugging

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

Source code fault injection is a testing technique where faults are systematically introduced into the source code to verify software resilience, making it highly effective for identifying incorrect pointer arithmetic, array boundary violations, and poor error handling.

Multiple choice technology security
  1. This is a double free vulnerability and must be fixed.

  2. The second call to free() will return an error.

  3. There might be compiler warnings, but the program will run fine.

  4. This is not a security issue.

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

Double free is a memory corruption vulnerability where free() is called twice on the same pointer. This can corrupt heap metadata, leading to crashes or arbitrary code execution. It is absolutely a security issue (D is wrong). The second free() does NOT necessarily return an error (B is wrong). The program will NOT run fine (C is wrong). Double free must be prevented by setting pointers to NULL after freeing or using memory-safe practices.

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

To limit the input length in C++ std::cin stream extractions, the manipulator setw or cin.width(n) is used. The syntax cin.width[20] contains a typo (should be parenthesis cin.width(20)), but it refers to using the width member function to prevent buffer overflow.

Multiple choice technology security
  1. delete j;

  2. realloc j;

  3. free j;

  4. It need not be deleted

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

argv[1] points to a string managed by the runtime environment, not dynamically allocated memory. Assigning it to j just copies the pointer value. Since no malloc/new/calloc was used, calling delete, free, or realloc on j is incorrect. The pointer should not be deleted.

Multiple choice technology security
  1. delete j

  2. free j

  3. it is not supposed to be deleted

  4. delete [] j

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

j is allocated with new char[100](array form), then immediately overwritten with argv[1], leaking the allocated memory. At the delete point, j points to the command-line argument string (not the allocated array), so deleting j would be wrong. However, the allocation itself should be freed before reassigning j. The question asks how to delete the pointer at the marked location, and the array form delete[] matches the original new[] allocation.

Multiple choice technology security
  1. value of tree

  2. value of node

  3. value of i

  4. garbage-- its a dangling pointer

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

myfunc returns a pointer to a local variable (tree or i). Both tree and i are local to myfunc and go out of scope when the function returns. The pointer in main becomes a dangling pointer pointing to freed stack memory. Dereferencing *leaf would access garbage values.

Multiple choice technology security
  1. Overwriting freed memory is a security vulnerability

  2. Depends on the application and how important “somedata” is

  3. This will result in a buffer overflow since the freed memory location cannot handle 8 characters of data “somedata”

  4. strcpy() will fail as it cannot write to already freed memory, and the application will crash.

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

Writing to freed memory (use-after-free) is a serious security vulnerability. After free(x), the memory is returned to the allocator and may be reallocated for other data structures. strcpy to this freed memory can corrupt those structures, leading to code execution exploits. This is not a buffer overflow (the string might fit), and strcpy does not automatically fail on freed memory - it succeeds, causing the corruption.

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 malloc() which allocates uninitialized memory. At line 3, newnum[i] += num reads and adds to uninitialized garbage values, producing unpredictable results. calloc() should be used instead because it zero-initializes memory, ensuring clean arithmetic. Also note the code has a typo - n is undefined (should be inputsize).

Multiple choice technology security
  1. /GS on Visual C++ and -fmudflap -fmudflapth -fmudflapir on GCC

  2. /O in Vc++ and -O2 in GCC

  3. /S in Vc++ and -fcrossjumping in GCC

  4. /S in VC++ and -fno-function-cse in GCC

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

The /GS flag in Visual C++ enables buffer overflow detection by adding security checks to compiled code. The GCC mudflap options (-fmudflap, -fmudflapth, -fmudflapir) provide similar runtime buffer overflow instrumentation. These compilation switches insert guard code to detect stack corruption and buffer overruns during program execution. Options B, C, and D refer to optimization and code generation settings unrelated to security checking.

Multiple choice technology security
  1. fstack-protector

  2. fstack-protector-all

  3. fdelete-null-pointer-checks

  4. Both a and b

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

-fstack-protector-all is the most secure option because it enables stack protection for all functions, regardless of their local variables. -fstack-protector only protects functions with vulnerable buffers (like char arrays of size 8 or larger).