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
-
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().
B
Correct answer
Explanation
In the C standard library printf function, specifiers like %a for hexadecimal floats, %c for characters, and %d for signed integers are all valid. The specifier %b is not a standard format specifier for printf in traditional C, making it invalid.
-
A method
-
A function
-
A statement
-
An operator
D
Correct answer
Explanation
In JavaScript, void is an operator that evaluates the expression next to it and returns undefined. It is not a method, function, or a flow-control statement.
D
Correct answer
Explanation
Pre-compile parameters in DB2 include Level (for optimization level), Host() (for specifying the host), and APost (for apostrophe handling). 'Time' is not a pre-compile parameter in DB2 - it may be confused with runtime parameters or other database systems, making it the correct answer for 'which is NOT a pre-compile parameter'.
C
Correct answer
Explanation
SEQNUM is the correct SORT option to generate sequence numbers. The syntax is typically SEQNUM=n where n specifies the starting position and length. NUMGEN and GENNUM are not valid SORT utility options for this purpose.
-
The program has a syntax error because the required break statement is missing in the switch statement.
-
The program has a syntax error because the required default case is missing in the switch statement
-
The switch control variable cannot be double.
-
No errors
C
Correct answer
Explanation
Java switch statements only work with integral types (byte, short, char, int) and their wrapper classes, enums, and String. A double variable like 'd' cannot be used as a switch expression because doubles are not integral and floating-point equality comparisons are unreliable. The break statement and default case are optional: their absence does not cause a syntax error.
-
#FIELDA (N3) = <100>
-
#FIELDA (N3) INIT <100>
-
#FIELDA (N3) INITIALISE <100>
-
ALL
B
Correct answer
Explanation
In Natural Cobol, variables are initialized using the INIT keyword followed by the initial value in angle brackets. The correct syntax is #FIELDA (N3) INIT <100>.
C
Correct answer
Explanation
Scalar variables store a single value and are referred to as name-value pairs because each variable name maps to exactly one value. Arrays store multiple indexed values, hashes store key-value pairs (which are also name-value pairs but for collections), and vectors are ordered collections. Option C is correct as scalars represent the simplest name-value pairing.
-
Extended expressions
-
Regular expressions
-
Irregular expressions
-
Basic expressions
B
Correct answer
Explanation
Regular expressions (regex) are the standard tool for validating complex string patterns like email addresses, phone numbers, postal codes, etc. Regex provides pattern-matching syntax that can express rules like 'must contain @ symbol' or 'must end with .com'. The other options (Extended, Irregular, Basic expressions) are not standard pattern validation mechanisms in programming.
-
Extended expressions
-
Regular expressions
-
Irregular expressions
-
Basic expressions
B
Correct answer
Explanation
Regular expressions provide powerful pattern matching for complex string validation like email addresses, phone numbers, or custom formats. ASP.NET's RegexValidator (or Regex class in System.Text.RegularExpressions) uses regex patterns to validate input against defined rules. Extended, irregular, and basic expressions are not standard terminology for this validation approach.
-
Static variables are global variables
-
static variales have local to the file/Scope they are declared , but exist throught the program life time
-
static variables are scoped, Meanaing that they will be destroyed once out of scope
-
Oh come on , Static variales are only in Java , Do not exist in C
-
static variales have local to the file they are declared , and they will be destroyed once out of scope
B
Correct answer
Explanation
Static variables in C have local scope (visible only within the function/block they're declared in) but static storage duration (they persist for the entire program execution). They retain their values between function calls and are initialized only once. This makes them different from both global variables (which have global scope) and automatic local variables (which are destroyed when out of scope).
-
It is just a fancy keyword, No purpose here
-
Prevents the compiler from assigning the function as an rvalue
-
Prevents the compiler from assigning the function as an lvalue
-
It makes sure that the return value is a const and is not changed by anyone else
C
Correct answer
Explanation
The const keyword before a function's return type (const int f(...)) prevents the function result from being used as an lvalue - you cannot assign to it. This means expressions like f() = 5 would be compile errors. The const refers to the return value being treated as read-only, not that it cannot be modified by others (option D is misleading - the returned value can still be modified if it's a reference/pointer).
-
Nothing is wrong. You are wrong.
-
Loops are not allowed inside the function scope, Since it degrades performance
-
My friend tried to return a pointer to a local function variable , which is invalid once the function call compltes.
-
The value i is not properly initialised, SO it may contain some garbage .
C
Correct answer
Explanation
The function returns a pointer to a local variable i. Local variables have automatic storage duration and are destroyed when the function returns. The returned pointer becomes a dangling pointer pointing to invalid memory. Using this pointer causes undefined behavior. This is a classic C/C++ error - never return pointers to local variables.
-
const int* ptr
-
const* int ptr
-
There is no such declaration like that
-
const int* const ptr
D
Correct answer
Explanation
The syntax const int* const ptr declares a pointer to a const int where both the pointer and the pointed-to value are const. The first const (before int) makes the value unchangeable through this pointer. The second const (after the *) makes the pointer itself unchangeable (it cannot point to a different address). Option A only protects the value, not the pointer.
-
They tell the C++ compiler that they are functions compiled by a C compiler , So that they can be used in C++
-
they mean that the function are declared somewhere and defined somewhere
-
They improve performance
-
They are used with extern variables.
A
Correct answer
Explanation
The extern C linkage specification tells the C++ compiler that the enclosed functions were compiled by a C compiler and should use C linkage rules. This disables C++ name mangling, allowing C++ code to link with C functions. Without this, C++ would mangle the function names, and the linker couldn't find the C functions.