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
-
Char i = 9
-
int i = 3/7
-
String i = "abc"
-
int i = 0
C
Correct answer
Explanation
In Java, adding a string to another string (i + 0) performs string concatenation (e.g., "abc" + 0 yields "abc0"). Since "abc" is not equal to "abc0", i != i + 0 evaluates to true, and it loops indefinitely. For numeric types, adding 0 does not change the value, so the loop terminates immediately.
-
A. Built-in
-
B. User-defined
-
C. User-function
-
D. Built-in, User-defined
-
E. Built-in, User-function
D
Correct answer
Explanation
Environment variables in shell/operating systems come in two main types: built-in variables provided by the system (like PATH, HOME, USER) and user-defined variables created by the user. Option D correctly identifies both types. Option C is incorrect because 'User-function' is not a type of environment variable.
-
A. For..Next, Select…..Case, Do…Loop
-
B. If…EndIf, For…Next, While…Wend
-
C. Do…loop, while…wend, select..case
-
D. Do..while, While…End, For…next
D
Correct answer
Explanation
QTP uses VBScript syntax for loops: Do...Loop (with Until/While), While...Wend, and For...Next. Option C lists Select..Case (a conditional, not a loop), and Options A/B mix incorrect combinations.
-
A. ++
-
B. Next
-
C. Skip
-
D. Step
D
Correct answer
Explanation
In VBScript (used by QTP), the 'Step' keyword controls the For loop counter increment (e.g., 'For i = 1 To 10 Step 2' increments by 2). '++' is C-style syntax, 'Next' just marks loop end, and 'Skip' isn't a VBScript keyword.
-
current date
-
current system date
-
future date
-
previous date
B
Correct answer
Explanation
The Date function in Visual Basic returns the current system date from your computer. It does not return past dates, future dates, or just the concept of 'current date' without system context - it specifically retrieves the date set in your system.
-
Current date and time
-
current date
-
current time
-
current date and future date
A
Correct answer
Explanation
The Now() function returns both the current date AND time as a single timestamp. Unlike Date() which returns only the date, Now() provides complete temporal information including hours, minutes, and seconds along with the calendar date.
-
current date
-
current time
-
current year
-
current month
D
Correct answer
Explanation
Month(Now) extracts just the month number (1-12) from the current date and time returned by Now(). It does not return the full date, time, or year - only the numeric month component.
-
Single line c++ syntax - //
-
Shell syntax - #
-
Both of above
-
None of above
C
Correct answer
Explanation
PHP supports both C++ style single-line comments (//) and shell style comments (#). This flexibility allows developers to choose their preferred commenting style or use both in the same codebase for different purposes.
-
echo ( )
-
print()
-
both
-
none
B
Correct answer
Explanation
print() returns 1 when output is successful, while echo() has no return value. This makes print() useful when you need to check if output succeeded, though echo() is slightly faster for simple output since it doesn't need to return a value.
-
echo()
-
print()
-
Printf()
-
none
C
Correct answer
Explanation
printf() is most suitable for blending static text with dynamic variables because it supports formatted strings with placeholders (%s, %d, etc.). This makes complex string construction more readable than concatenation with echo() or print().
-
Declare cookie variables
-
Store data in cookie variable
-
Enable or disable cookie support
-
All of the above
B
Correct answer
Explanation
The setcookie() function in PHP sends a cookie to the browser, storing data in a cookie variable that will be sent back with subsequent requests. It does not declare variables (that's just variable assignment) nor does it enable/disable cookie support (that's controlled by browser settings).
-
Faster
-
Slower
-
The execution speed is similar
-
All of above
B
Correct answer
Explanation
Scripts run slower than compiled programs because they are interpreted line-by-line at runtime, while compiled programs are already converted to machine code. The interpreter adds overhead for parsing and translating each instruction before execution.
-
Local
-
function parameter
-
static
-
None of above
C
Correct answer
Explanation
Static variables retain their value between function calls because they are allocated in static memory and persist across function invocations. Local variables are destroyed when the function returns, and function parameters are reinitialized on each call.
-
Local variables
-
Function parameters
-
Hidden variables
-
Global variables
C
Correct answer
Explanation
PHP supports local variables (function-scoped), global variables (accessible with global keyword or $GLOBALS), and function parameters. 'Hidden variables' is not a recognized scope type in PHP - the language only has local, global, static, and function parameter scopes.