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
-
Heap
-
Stack
-
Code Segment
-
Data Segment
B
Correct answer
Explanation
The variable test1 is a local non-static variable declared inside the func() function, so it is allocated on the stack. Local variables (automatic storage duration) are created on the stack when the function is called and destroyed when the function returns. Heap is for dynamic allocation (malloc), code segment for instructions, and data segment for static/global variables.
B
Correct answer
Explanation
In REPEAT operations, setting count to 0 executes the code exactly once. Setting it to 1 would execute twice, while -1 would create an infinite loop. This counterintuitive behavior exists because count represents the number of repetitions to perform after the first execution.
-
Byte Code
-
Firewall
-
Tetra Code
-
View Code
A
Correct answer
Explanation
Bytecode is a highly optimized set of instructions designed to be executed by the Java runtime system (JVM). When Java source code is compiled, it produces bytecode which is a compact, platform-independent representation that the JVM interprets or compiles further into native machine code.
-
will execute
-
will not execute
-
Compilation Error
-
Runtime Exception
A
Correct answer
Explanation
In Java, the finally block is guaranteed to execute even if there is a return statement in the try or catch block, ensuring clean-up code is always run.
B
Correct answer
Explanation
The code compiles successfully because k is initialized to 0 by default. The loop condition k<10 is true initially, so the loop body runs. After that, k remains 0 while i increments, so this becomes an infinite loop (until integer overflow). The issue is a logical error, not a compilation error.
-
a) getenv(), setenv()
-
b) getenv(), putenv()
-
c) readenv(), writeenv()
-
d) You cannot environmement variables inside a program
B
Correct answer
Explanation
getenv() retrieves environment variable values, while putenv() sets or modifies them. These are standard C library functions for environment variable manipulation. Options A uses setenv() which also exists but the question asks for the standard pair.
-
a) 2nd
-
b) Ist
-
c) 3rd
-
d) 4th
A
Correct answer
Explanation
SessionFactory is associated with the second-level cache in Hibernate. The first-level cache is at the Session level and is enabled by default, while the second-level cache is at the SessionFactory level and is optional.
-
a) 2nd
-
b) Ist
-
c) 3rd
-
d) 4th
A
Correct answer
Explanation
In Hibernate, the SessionFactory is responsible for managing the second-level (2nd) cache, which is shared across all sessions. The Session object manages the first-level (1st) cache, which is transaction-scoped.
-
a) By using the mutable="false" attribute in the class mapping.
-
b) By using the ismutable="false" attribute in the class mapping.
-
c) By using the ismutable="no" attribute in the class mapping.
-
d) None
A
Correct answer
Explanation
In Hibernate ORM mapping, the mutable="false" attribute tells Hibernate that the entity's state never changes after initialization. This allows Hibernate to optimize performance by skipping dirty checking during flush operations for this entity. The ismutable attribute name doesn't exist in Hibernate.
A
Correct answer
Explanation
The system() function in C/C++ executes a shell command and returns an implementation-defined value that can be processed. Typically, it returns the exit status of the command (or 0 on success, -1 if fork fails, or another value if the shell could not be executed). Programmers routinely check this return value to determine if the command succeeded or failed, making it processable.
-
NULLIF
-
LENGTH
-
CONCAT
-
INSTR
-
TAN
C
Correct answer
Explanation
CONCAT can return non-null when passed NULL arguments. In most SQL dialects, CONCAT with NULL arguments treats NULL as an empty string, producing a non-NULL result. For example, CONCAT(NULL, 'a') or CONCAT(NULL, NULL) typically returns a non-null string (empty or partial result). Other functions like LENGTH, NULLIF, INSTR, TAN generally return NULL when any argument is NULL.
-
function_name() {command-list }
-
function_name ( ) { }
-
function name (command list ) {
-
None
A
Correct answer
Explanation
Shell functions are declared using the function_name() { command-list; } syntax. The function name is followed by empty parentheses, then a command list enclosed in braces. This is the standard POSIX-compliant function declaration format in bash and other Unix shells.
-
stdout
-
stderr
-
stderr2
-
stdouterr
B
Correct answer
Explanation
stderr (standard error, file descriptor 2) is the Unix stream specifically for error messages and diagnostics. stdout is for standard output (file descriptor 1). The other options (stderr2, stdouterr) are not standard stream names.
-
while,until
-
until, while
-
repeat, while
-
None
A
Correct answer
Explanation
while loops continue as long as the condition returns true (exit status 0). until loops continue until the condition becomes true, meaning they execute when the condition returns false (non-zero exit status). This is the inverse logic of while loops.