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
-
$global:a = 1
-
$public:a = 1
-
$private:a = 1
-
$local:a = 1
B
Correct answer
Explanation
PowerShell variable scopes are: global, script, local, private, and (for modules) exported. 'public' is NOT a valid scope modifier. Options A, C, D are valid scope declarations.
D
Correct answer
Explanation
In PowerShell, the Trap statement is used to catch and handle terminating errors. It's similar to try/catch in other languages. Catch is used with Try, Throw raises errors, and Get is for retrieval.
B
Correct answer
Explanation
The Break statement is used in PowerShell to exit loop constructs like ForEach, For, While, Do-While, and Switch statements. Exit terminates the entire script or console session. Return exits a function or script block. Jump is not a valid PowerShell keyword for loop control.
-
Variables in the global scope are visible in all scopes
-
Variables in the script scope are visible to all scopes within that script file.
-
Variables in the local scope are visible only in the current scope and not to its children.
-
Private scope variables are visible only to that current scope.
A,B,D
Correct answer
Explanation
Global scope variables are accessible from anywhere in PowerShell. Script scope variables are visible throughout the script file. The statement C is incorrect because local scope variables ARE inherited by child scopes - they remain visible in nested scopes. Private scope is the only scope that doesn't inherit to children.
-
Mandatory
-
Named
-
Generic
-
Positional
C
Correct answer
Explanation
PowerShell parameter attributes include Mandatory, Positional, and Named (parameters you specify by name). Generic is not a valid PowerShell parameter type - there is no [Generic()] attribute in PowerShell. Parameter types can be string, int, bool, etc., but Generic is not a parameter classification.
-
Tom drives a fast car
-
Tom drives a $strA car.
-
Tom drives a “fast” car.
-
none of the above
B
Correct answer
Explanation
PowerShell single quotes treat everything literally - $strA is not expanded but treated as the literal string '$strA'. Double quotes would expand variables. The output is exactly 'Tom drives a $strA car.' with the variable name displayed, not its value 'fast'.
-
It is a defect
-
It is a defect which requires more information
-
It is a defect which will be fixed later during the course of the project
-
It is not a defect
C
Correct answer
Explanation
A deferred defect is a confirmed defect that is intentionally postponed for fixing until a later time during the project lifecycle. This typically happens due to factors like project deadlines, risk assessment, or resource allocation. The defect is documented and tracked but not immediately addressed. Option A is incomplete - deferred defects are defects, but the definition misses the key temporal aspect. Option B describes a defect needing clarification, while option D incorrectly denies it's a defect.
-
It is a defect
-
It is a defect which requires more information
-
It is a defect which will be fixed later during the course of the project
-
It is not a defect
C
Correct answer
Explanation
A deferred defect is a confirmed defect that is documented but intentionally not fixed immediately - it will be addressed later in the project. This might happen due to time constraints, low priority, or plans to fix it during a later phase. Option A is technically true but too vague. Option B describes a defect needing clarification, not deferral. Option D is incorrect - it IS a defect, just postponed.
-
A method
-
A function
-
A statement
-
An operator
D
Correct answer
Explanation
void is a JavaScript operator that evaluates an expression and returns undefined. It's commonly used to prevent expressions from returning a value (like void 0 for undefined). It's not a method (A), function (B), or statement (C).
-
create myFunction()
-
function myFunction()
-
new_function myFunction()
-
calling_funtion myFunction()
B
Correct answer
Explanation
PHP functions are declared using the 'function' keyword followed by the function name and parentheses. Option A is missing the function keyword, options C and D use incorrect syntax that doesn't exist in PHP.
-
arguments.length
-
Function.caller
-
Function.display
-
Function.arity
D
Correct answer
Explanation
Function.arity returns the number of arguments expected by a function. Option A's arguments.length returns the actual number of arguments passed, not expected. Options B and C are non-existent properties.
-
they can be sorted by type
-
they can be called at runtime
-
name functions does not exist
-
they can be sorted by value
B
Correct answer
Explanation
The name function in controls allows them to be called at runtime. Name functions do exist in programming contexts, and while controls can be sorted, that's not the primary purpose of the name function.
-
Different names
-
Same name
-
Both 1 and 2
-
None of these
B
Correct answer
Explanation
A control array in Visual Basic is a collection of controls that share the same name, allowing them to be accessed and manipulated as a group. Option B is correct - control arrays have the same name with different index values. Options A, C, and D are incorrect - controls in an array cannot have different names, and this is not an either/or situation.
B
Correct answer
Explanation
In Java, 'if', 'goto', 'while', and 'case' are all reserved keywords. The word 'then' is not a Java keyword, even though it's used in other languages like Pascal. Java uses if(condition) { } syntax without a 'then' keyword.