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
-
as and when required
-
at the end of the compilation process
-
at the beginning of the compilation process
-
while running the program
C
Correct answer
Explanation
The C preprocessor processes directives (like #include, #define) at the beginning of compilation, before the actual compilation phase. This is why preprocessor directives can't use C syntax - they're processed by a separate program that prepares the source code for the compiler.
A
Correct answer
Explanation
In C++, functions can return references or pointers to variables, allowing for modifications to the original data through the return value. This is useful for operator overloading and chaining operations. However, care must be taken not to return references to local variables that go out of scope.
-
bad()
-
good()
-
eof()
-
fail()
D
Correct answer
Explanation
The fail() function returns true when a stream operation fails, including when an input/output operation on a file fails. This sets the failbit in the stream state. The bad() function is for serious errors like stream corruption, good() returns true if no errors occurred, and eof() checks for end-of-file condition specifically.
-
address of operator
-
reference operator
-
value operator
-
indirection operator
D
Correct answer
Explanation
The * operator in C++ is called the indirection operator or dereference operator because it accesses the value at the address stored in a pointer. It is the opposite of the address-of operator (&). Address and reference operators are different concepts.
A
Correct answer
Explanation
External variables (declared with extern keyword) are automatically zero-initialized in C/C++. This ensures global and external variables start with a predictable value when no explicit initialization is provided.
A
Correct answer
Explanation
In C, external (global) variables are automatically initialized to 0 if not explicitly initialized. This applies to both external variables and static variables. Local variables, however, are not automatically initialized and contain garbage values.
-
translation time
-
compilation time
-
run time
-
none of the above
C
Correct answer
Explanation
Exceptions occur during program execution (runtime) when something unexpected happens - like division by zero, null pointer access, or file not found. Compile-time errors are syntax errors caught by the compiler, while runtime exceptions happen while the program is running.
-
Part 1
-
Part 2
-
Part 3
-
No Error
B
Correct answer
Explanation
Part 2 (class=" no error") contains a syntax error - there should be no leading space before the class name. In HTML/Java applet tags, attribute values should not have leading/trailing spaces unless intended. The correct syntax would be class="noerror" or class="MyApplet.class".
-
Use sub string
-
Use one argument
-
Use sub str
-
Use two arguments
A
Correct answer
Explanation
The error occurs because Java is case-sensitive and String methods have specific names. The correct method name is 'substring()' not 'subStr()'. The space in 'sub Str' also causes compilation error. Java String objects use camelCase naming convention for methods like substring(), indexOf(), charAt().
-
constants
-
function
-
type definitions
-
parables
B
Correct answer
Explanation
In programming, a function is a self-contained module that performs a specific task or computation. Constants are fixed values, type definitions define data structures, and 'parables' is not a programming term. Functions are fundamental building blocks that promote code reusability and organization.
-
compilation
-
debugging
-
loading
-
execution
D
Correct answer
Explanation
Runtime errors occur only during program execution when the computer attempts an invalid operation (like division by zero or accessing invalid memory). Compile-time errors are caught during compilation, and debugging/loading are processes, not error-detection phases.
-
Repetition
-
Selection
-
Sequence
-
Switching
C
Correct answer
Explanation
Sequence is fundamental - every program executes statements sequentially (one after another) by default. Even the simplest program must execute statements in order. Selection (if/else) and repetition (loops) are optional control structures that programs may or may not use. "Switching" is not a standard control structure category.
-
reads a line of string from cin into mystring
-
reads a line of string from mystring into cin
-
cin cannot be used in this way
-
Function declaration is wrong
A
Correct answer
Explanation
The getline(cin, mystring) function reads a complete line of text from the input stream (cin) and stores it in the string variable mystring. Unlike cin >> mystring which stops at whitespace, getline reads until a newline character. Option B is reversed (cin is the source, not destination). Option C is incorrect because getline is a standard valid function.
-
Start ( )
-
Begin( )
-
Main ( )
-
Output( )
C
Correct answer
Explanation
main() is the designated entry point where C++ program execution begins. When you run a C++ program, the operating system calls the main() function first. Options like Start(), Begin(), or Output() are not standard entry points in C++. The exact signature is typically int main() for standards-compliant code.
-
Any modifications to the variables x & y from inside the function will not have any effect outside the function.
-
The variables x and y will be updated when any modification is done in the function.
-
The variables x and y will be passed back to the function addition.
-
The result of a function cannot be assigned to a variable Z.
A
Correct answer
Explanation
When arguments are passed by value, the function receives copies of the original values. Any modifications made to x and y inside the function affect only the local copies - the original variables outside remain unchanged. This is why pass-by-reference (using &) is needed when you want modifications to affect the originals. Option C describes pass-by-reference behavior, and option D is incorrect because function results can be assigned to variables.