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
-
Nothing is wrong
-
Break is not used in case 2
-
Default is not there
-
Num4 = 400 is not reachable
A
Correct answer
Explanation
Though num 4 is not reachable but as for as code is concerened there is nothing wrong. May be the programmer wants it like that.
-
true
-
false
-
Depends on the exception.
-
None
C
Correct answer
Explanation
There may not be a termination for throwing an exception, it depends on the exception itself whether it should be terminated or not.
-
float[ ] marks
-
number = new int[5]
-
int product [ ] [ ]
-
float num{ }
D
Correct answer
Explanation
In Java, array declaration syntax requires square brackets []. Option D uses curly braces {}, which is incorrect for array declaration.
-
By avoiding goto statements
-
By using meaningful and indicative names of variables and functions
-
By using modular programming
-
All of the above
D
Correct answer
Explanation
Readability is improved by using clear naming conventions, avoiding complex control flow like goto, and utilizing modular programming to break code into manageable pieces.
-
from the point of definition onward in the program
-
throughout the function
-
from the point of definition onward in the function
-
from the point of definition onward in the block
D
Correct answer
Explanation
In C++, a variable defined within a block (enclosed by curly braces) has block scope. It is only accessible from the point of its declaration until the end of that specific block.
-
are a group of functions with the same name
-
make life harder for programmers
-
may fail unexpectedly due to over stress
-
all have same number and type of arguments
A
Correct answer
Explanation
Function overloading allows multiple functions to share the same name provided they have different parameter lists (different number or types of arguments). This improves code readability and reuse.
-
returns a pointer to a variable
-
creates a variable called new variable
-
clears memory for a new variable
-
tells how much memory is available
A
Correct answer
Explanation
The 'new' operator in C++ allocates memory dynamically on the heap and returns the address of the allocated memory, which is stored in a pointer variable.
-
only from the innermost loop
-
only from the innermost switch
-
from the innermost loop or switch
-
from all loops or switches
C
Correct answer
Explanation
The 'break' statement is used to terminate the execution of the nearest enclosing loop (for, while, do-while) or switch statement. It does not exit nested loops or switches beyond the immediate one.
-
synchronous exceptions
-
asynchronous exceptions
-
all of above
-
none of these
B
Correct answer
Explanation
Asynchronous exceptions are caused by events external to the program, such as hardware interrupts or user input, which the program cannot predict or control directly.
D
Correct answer
Explanation
In C++, the throw keyword is used to signal that an exception has occurred. Try and catch are used to handle the exception, while struct is a data structure definition.
-
keywords
-
constants
-
tokens
-
operators
A
Correct answer
Explanation
Keywords are reserved words in a programming language that have a predefined meaning and cannot be used as identifiers for variables, functions, or classes.
-
an operator
-
a label
-
a function
-
a variable
B
Correct answer
Explanation
The goto statement is an unconditional jump that transfers program control to a labeled statement within the same function.
-
the flow of control through a function
-
a flow of data from one place to another
-
not related to a class
-
takes no arguments
B
Correct answer
Explanation
In C++, a stream is an abstraction that represents a device on which input and output operations are performed. It acts as a flow of data between a source and a destination.
-
password
-
pointer
-
picture
-
overlay
-
None of these
C
Correct answer
Explanation
In COBOL, the PICTURE clause is used to define the format, length, and data type (numeric, alphabetic, etc.) of a data item.