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
-
a. continue;
-
b. break;
-
c. return "Infant";
-
d. return 0;
C
Correct answer
Explanation
The function declares a string return type but has no return statement for ages 4 and below. Adding 'return "Infant";' as the last line ensures all execution paths return a string, satisfying the compiler's requirement that non-void functions must return a value on all paths.
-
a. true
-
b. false
-
c. sometimes
-
d. depends
B
Correct answer
Explanation
The first enum member defaults to 0, not 1, even though the underlying type is integer. This is true for C#, C++, Java, and most other languages. The default type is indeed integer, but the automatic value assignment starts at 0 unless explicitly specified.
-
a. true
-
b. false
-
c. an exception is thrown
-
d. depends
C
Correct answer
Explanation
Unboxing extracts a value type from an object reference. If that reference is null, there's nothing to extract, causing a runtime exception (NullReferenceException in C#). You cannot unbox null because unboxing requires an actual boxed value to retrieve.
-
a. Yes
-
b. No
-
c. Under certain conditions
-
d. May be
B
Correct answer
Explanation
Only ONE catch block executes for a given exception. Exception handlers are evaluated in order, and the first matching catch block handles the exception. Once executed, control jumps to the finally block (if any) and then continues after the try-catch structure. No other catch blocks run for that same exception.
-
a. readonly value can be changed later
-
b. const items are dealt at compile time however readonly is dealt at runtime
-
c. const value can be changed later
-
d. const items are dealt at runtime however readonly is dealt at compile time
B
Correct answer
Explanation
const is a compile-time constant - the value is embedded at compile time and cannot change. readonly is a runtime constant that can be assigned once (at declaration or in a constructor) and then becomes immutable. This is why const can only be used for value types and string literals, while readonly can reference any type.
-
memory
-
register
-
variable
-
assembler
D
Correct answer
Explanation
Operands are the data values that instructions operate on. Memory locations, registers, and variables can all serve as operands as they hold or reference data values. An assembler is a software tool that converts assembly language to machine code - it is not an operand but rather a program that processes instructions containing operands.
B
Correct answer
Explanation
Java's reserved words are: if, else, while, for, case, goto (reserved but unused), switch, etc. 'then' is NOT a Java keyword - it's used in some other languages but not in Java's syntax. This makes 'then' the correct answer.
C
Correct answer
Explanation
Both syntax examples (1 and 2) are valid. In option 1, setProperty is nested inside the useBean body. In option 2, setProperty appears after the useBean tag closes. Both approaches work correctly - the nested approach is more compact while the separate approach is more flexible. Therefore option C 'both' is correct.
-
Address of the array
-
Values of the first elements of the array
-
Address of the first element of the array
-
Number of element of the array
-
float ptr;
-
float *ptr;
-
*float ptr;
-
None of the above
B
Correct answer
Explanation
In C, a pointer to float is declared using an asterisk (*) before the variable name: float *ptr;. Option A (float ptr;) declares a regular float variable, not a pointer. Option C (*float ptr;) has incorrect syntax - the asterisk must come after the type, not before it.
-
exception
-
harness
-
assertion
-
expression
C
Correct answer
Explanation
An assertion is a statement that a programmer believes should always be true at a specific point in code execution. Assertions are used as debugging and testing aids to check assumptions during development, and typically trigger an error or exception if the condition evaluates to false.
B
Correct answer
Explanation
Java does not use 'then' as a keyword. Words like 'if', 'while', 'case' are keywords. 'goto' is a reserved word (not used but reserved for future potential use).
-
At least one variable must be added to a Global Variable group
-
The predefined value of a Global Variable cannot be overridden from the command line
-
The predefined value of a Global Variable for individual services can be changed at deployment time
-
When using a Global Variable in the fields of a resource, enter the name surrounded by $
A,C
Correct answer
Explanation
A Global Variable group must contain at least one variable to be valid. Global Variable values can be overridden at deployment time for individual services. Global Variables can be overridden from the command line using the -var option, and they are referenced in resources using the syntax %%globalVariableName%%, not with $.
-
Job Shared Variables can be modified at run-time, and Shared Variables cannot
-
Shared Variables can be shared across process engines, and Job Shared Variables cannot
-
Shared Variables can be shared across process instances, and Job Shared Variables cannot
-
Job Shared Variables can be shared across process definitions in a project, and Shared Variables cannot
B,C
Correct answer
Explanation
Shared Variables can be shared across multiple process engines in a distributed environment, while Job Shared Variables are confined to a single job instance. Shared Variables can also be shared across process instances within the same engine, but Job Shared Variables cannot be shared across different process instances. Both variable types can be modified at runtime, and Job Shared Variables are not scoped across process definitions.
B
Correct answer
Explanation
In Java, 'then' is NOT a keyword or reserved word. Java's conditional statement uses 'if' and 'else' - 'then' is not part of the syntax. The other options ARE keywords or reserved words: 'if' is a conditional keyword, 'goto' is a reserved word (though not used), 'while' is a loop keyword, and 'case' is used in switch statements. This question tests knowledge of Java's reserved word list.