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

Multiple choice .net
  1. Logic

  2. Runtime

  3. Superficial

  4. Syntax

  5. All are errors programmers look for.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Programmers focus on syntax errors (code structure violations), runtime errors (failures during execution), and logic errors (code runs but produces wrong results). 'Superficial' is not a standard error classification in programming - it doesn't represent a category of bugs developers actively track.

Multiple choice .net
  1. Dividing by zero.

  2. Assigning the string "Hi" to an integer variable.

  3. Accessing an empty CD drive.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

An exception is an error that occurs during execution. Dividing by zero, attempting to store incompatible types (like a string in an integer), or hardware errors like accessing an empty drive all trigger runtime exceptions in the .NET environment.

Multiple choice .net
  1. compile error.

  2. logic error.

  3. runtime error.

  4. superficial error.

  5. syntax error.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

An exception is an event that disrupts normal program execution during runtime - like division by zero or accessing a null reference. These are runtime errors because they occur while the program is running, not during compilation. Logic errors produce wrong results without crashing, syntax errors prevent compilation, and 'superficial error' isn't a standard category.

Multiple choice .net
  1. Event

  2. Function

  3. Sub

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

To answer this question, the user needs to have some basic knowledge of VB.Net programming language and its concepts.

The answer is E. All of the above.

Explanation:

In VB.Net, there are two types of procedures: Functions and Subs. Both Functions and Subs are used to group a set of statements that perform a specific task.

Functions are procedures that return a value after performing a specific task. Functions are defined using the "Function" keyword.

Subs are procedures that do not return a value after performing a specific task. Subs are defined using the "Sub" keyword.

Events are not procedures, but rather they are actions that occur in response to user actions or system events. Events are used to trigger a specific action or set of actions in an application.

Therefore, option D is incorrect because Events are not a type of procedure in VB.Net. Option E is correct because both Functions and Subs are types of procedures found in VB.Net.

The answer is: E. All of the above.

Multiple choice .net
  1. event-driven programming.

  2. functional programming.

  3. granular programming.

  4. modular programming.

  5. procedural programming.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To solve this question, the user should be familiar with different programming methodologies and their characteristics. The user should be able to identify the methodology where code is broken into small, logical procedures.

Option A: Event-driven programming is a programming paradigm where the flow of the program is determined by events such as user actions (clicking a button), sensor outputs, or messages from other programs/threads. This option is incorrect because it is not the methodology where code is broken into small, logical procedures.

Option B: Functional programming is a programming paradigm where programs are constructed by applying and composing functions. This option is incorrect because it is not the methodology where code is broken into small, logical procedures.

Option C: Granular programming is not a widely recognized methodology in programming. This option is incorrect.

Option D: Modular programming is a methodology where code is broken down into independent, interchangeable modules that can be used in different parts of the program. This option is the correct answer.

Option E: Procedural programming is a programming paradigm where the program is structured around procedures, or subroutines, that perform specific tasks. This option is similar to option D but does not emphasize the independence and interchangeability of the modules.

Therefore, the answer is: D. modular programming.

Multiple choice .net
  1. actual argument to the formal parameter of the procedure.

  2. formal argument to the actual parameter of the procedure.

  3. actual parameter to the formal argument of the procedure.

  4. formal parameter to the actual argument of the procedure.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To understand the question, the user needs to know about procedures and the concepts of formal and actual parameters.

When a procedure is called, data is passed from the calling code to the procedure. This data is referred to as the argument of the procedure, and can be either a value or a variable. The calling code specifies the argument by providing a value or a variable name.

Formal parameters are the parameter names declared in the procedure header, while actual parameters are the arguments passed to the procedure during the call.

Now, let's go through each option and explain why it is right or wrong:

A. actual argument to the formal parameter of the procedure.

This option is correct. The actual argument is the value or variable passed to the procedure during the call. It is assigned to the formal parameter, which is the parameter name declared in the procedure header.

B. formal argument to the actual parameter of the procedure.

This option is incorrect. The formal argument is not a commonly used term in programming. The parameter name declared in the procedure header is called the formal parameter, not the formal argument.

C. actual parameter to the formal argument of the procedure.

This option is incorrect. The actual parameter is the argument passed to the procedure during the call, while the formal argument is not a commonly used term in programming.

D. formal parameter to the actual argument of the procedure.

This option is incorrect. The formal parameter is the parameter name declared in the procedure header, while the actual argument is the value or variable passed to the procedure during the call.

E. All of the above.

This option is incorrect. Only option A is correct.

Therefore, the answer is: A. actual argument to the formal parameter of the procedure.

Multiple choice .net
  1. e

  2. Sender

  3. Receiver

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

An event procedure is a block of code that is executed in response to an event, such as a button click or a form load. When an event is triggered, the event procedure is called and passed certain parameters that provide information about the event.

The parameters that are found in an event procedure may vary depending on the programming language or platform being used, but they generally include the following:

A. e - This parameter represents the event arguments, which provide information about the event that was raised. It may include properties such as the name of the control that raised the event, the type of event, and any additional data associated with the event.

B. Sender - This parameter represents the object that raised the event. It is typically used to identify the control or component that triggered the event.

C. Receiver - This parameter is not commonly found in event procedures, but it may refer to the object or component that is listening for the event.

Therefore, the correct answer is E, all of the above. Both parameter e and Sender are commonly found in event procedures, and in some cases, Receiver may also be present.

Multiple choice .net
  1. End Sub

  2. Handles

  3. Object_Event

  4. Statements

  5. Sub

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

An event procedure is a subroutine that is called in response to an event. The event procedure is defined using the Sub keyword, followed by the name of the event procedure, the Handles keyword, and the name of the event. The event procedure can contain any number of statements.

The End Sub keyword is not optional, as it marks the end of the event procedure. The Handles keyword is also not optional, as it specifies the event that will trigger the event procedure. The Object_Event identifier is optional, and it can be used to specify the object and event that will trigger the event procedure. The Statements are optional, as the event procedure can be empty.

Correct Option: D. Statements

The Statements element is optional in an event procedure. The event procedure can be empty, or it can contain any number of statements. The statements in the event procedure will be executed when the event is triggered.

Here is an example of an event procedure:

Sub btnClick(sender As Object, e As EventArgs)
'This is an event procedure that is triggered when the button is clicked.
'The event procedure contains two statements.

MsgBox("The button was clicked!")
End Sub

As you can see, the event procedure contains two statements. The first statement displays a message box, and the second statement ends the event procedure.

Multiple choice .net
  1. Only arguments of numeric data types are allowed.

  2. A reference to the argument is sent to the procedure.

  3. A copy of the argument is sent to the procedure.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To understand what happens when a parameter in a procedure is declared ByVal, the user needs to have knowledge of programming concepts and specifically the concept of passing arguments to procedures.

When a parameter is declared ByVal, it means that a copy of the argument is sent to the procedure. This means that any changes made to the parameter inside the procedure will not affect the original argument in the calling code.

Now, let's go through each option and explain why it is right or wrong:

A. Only arguments of numeric data types are allowed: This option is incorrect. When a parameter is declared ByVal, it is not restricted to only numeric data types. It can be used with arguments of any data type.

B. A reference to the argument is sent to the procedure: This option is incorrect. When a parameter is declared ByVal, a reference to the argument is not sent. Instead, a copy of the argument is sent to the procedure.

C. A copy of the argument is sent to the procedure: This option is correct. When a parameter is declared ByVal, a copy of the argument is sent to the procedure. This means that any changes made to the parameter inside the procedure will not affect the original argument in the calling code.

D. Both a and b: This option is incorrect. Option a is incorrect because arguments of any data type are allowed, not just numeric data types. Option b is incorrect because a reference to the argument is not sent when the parameter is declared ByVal.

E. All of the above: This option is incorrect. Option a is incorrect, and option b is incorrect. Only option c is correct.

Therefore, the correct answer is:

The Answer is: C

Multiple choice .net
  1. makes code easier to maintain.

  2. splits the logic to solve a problem into small, manageable units.

  3. limits the number of times the code can be accessed.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To solve this question, the user needs to have knowledge of programming concepts and the purpose of sub procedures.

A sub procedure, also known as a subroutine or function, is a block of code that performs a specific task or set of tasks within a larger program. It is called by the main program and helps in organizing and modularizing the code.

Now, let's go through each option and explain why it is right or wrong:

A. makes code easier to maintain: This option is correct. By using sub procedures, the code is divided into smaller units, making it easier to understand, debug, and maintain. Changes or updates can be made to a specific sub procedure without affecting the entire code.

B. splits the logic to solve a problem into small, manageable units: This option is correct. Sub procedures help in breaking down complex problems into smaller, more manageable tasks. Each sub procedure focuses on solving a specific part of the problem, making the overall logic easier to understand and implement.

C. limits the number of times the code can be accessed: This option is incorrect. Sub procedures do not limit the number of times the code can be accessed. They can be called multiple times from different parts of the program as needed.

D. Both a and b: This option is correct. Both options A and B are correct, as explained above. Sub procedures make code easier to maintain and split the logic into small, manageable units.

E. All of the above: This option is incorrect. Option C is incorrect because it does not accurately describe the purpose or benefit of sub procedures. Sub procedures do not limit the number of times the code can be accessed.

Therefore, the correct answer is:

D. Both a and b.

Multiple choice .net
  1. Parameters

  2. Public

  3. Private

  4. Statements

  5. Sub

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The correct answer is E. Sub.

The Sub keyword is not an optional element of a sub procedure declaration. It is used to declare the start of a sub procedure. The other elements, such as parameters, public, private, and statements, are optional.

Here is an example of a sub procedure declaration:

Sub MySub()

' This is the body of the sub procedure.

End Sub

As you can see, the Sub keyword is the first element in the declaration. The other elements are optional.

Here is a table that summarizes the optional elements of a sub procedure declaration:

Element Description
Public Indicates that the sub procedure is accessible to all other procedures in all modules.
Private Indicates that the sub procedure is accessible only to other procedures in the module where it is declared.
Parameters A list of variables that are passed to the sub procedure when it is called.
Statements The body of the sub procedure. This is where the code that executes when the sub procedure is called is placed.
Multiple choice .net
  1. Use the Class and Method combo boxes in the Code Editor window.

  2. Double click on the object in the Form Designer window.

  3. Type the procedure declaration in the Code Editor window.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To write a sub procedure declaration, the user needs to know how to declare a sub procedure in the programming language they are using. The options provided are methods to write a sub procedure declaration in different programming environments.

Now, let's go through each option and explain why it is right or wrong:

A. Use the Class and Method combo boxes in the Code Editor window. This option is specific to certain programming environments that have a Code Editor window with Class and Method combo boxes. If the programming environment being used provides this feature, then it can be a valid way to write a sub procedure declaration in that specific environment.

B. Double click on the object in the Form Designer window. This option is specific to programming environments that have a Form Designer window. Double-clicking on an object in the Form Designer window can create an event handler for that object, which includes the sub procedure declaration. If the programming environment being used has this feature, then it can be a valid way to write a sub procedure declaration in that specific environment.

C. Type the procedure declaration in the Code Editor window. This option is a general way to write a sub procedure declaration in any programming environment that provides a Code Editor window. The user can manually type the procedure declaration in the Code Editor window, specifying the name, parameters, and return type (if applicable) of the sub procedure.

D. Both a and b. This option is incorrect because it only includes options A and B. Option C is not included.

E. All of the above. This option is incorrect because it includes all options A, B, and C. Option D is not included.

Therefore, the correct answer is:

C. Type the procedure declaration in the Code Editor window.

Multiple choice .net
  1. Return Sales*0.08

  2. CalculateTax = Sales*0.08

  3. Return CalculateTax (Sales*0.08)

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To send the value generated by a function procedure back to the calling code, you need to use the "return" statement.

Option A) Return Sales*0.08 - This option is correct because it uses the "return" statement to send the value of Sales multiplied by 0.08 back to the calling code.

Option B) CalculateTax = Sales*0.08 - This option is incorrect because it assigns the value of Sales multiplied by 0.08 to the variable CalculateTax, but it does not send the value back to the calling code.

Option C) Return CalculateTax(Sales*0.08) - This option is incorrect because it tries to call the CalculateTax function recursively, which is not necessary and can lead to an infinite loop.

Option D) Both a and b - This option is correct because it includes both the correct options A and B.

Option E) All of the above - This option is incorrect because option C is incorrect.

Therefore, the correct answer is D) Both a and b.

Multiple choice .net
  1. Datatype

  2. Function

  3. Parameters

  4. Private

  5. ProcedureName

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A function declaration can omit parameters if it takes no arguments - the empty parentheses are still required but the parameter list between them can be empty. However, the keyword 'Function', the return Datatype, the ProcedureName, and scope modifiers like 'Private' are all essential parts of the declaration syntax.

Multiple choice .net
  1. 1

  2. 2

  3. 3

  4. There is no limit.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Function procedures can have multiple return statements - you can return from different points based on conditional logic. While good practice often suggests a single exit point, the language allows unlimited return statements anywhere in the function body. Each return statement must specify a value of the function's return type.