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

Multiple choice .net
  1. selects a block of statements to run.

  2. runs the same block of statements repeatedly.

  3. selects a block of statements and runs it repeatedly.

  4. selects a block of statements and runs it a specified number of times.

  5. All of the above.

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

The Do...Loop is categorized as an iterative (looping) statement because its primary purpose is to execute a specific block of code repeatedly as long as (or until) a certain condition is met.

Multiple choice .net
  1. The While condition goes after the Do keyword.

  2. The Until condition goes after the Do keyword.

  3. The While condition goes after the Loop keyword.

  4. The Until condition goes after the Loop keyword.

  5. All of the above.

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

Do...Loop structures support both While and Until conditions, and these conditions can be placed either after the Do keyword (pre-test) or after the Loop keyword (post-test). Therefore all four arrangements (While after Do, Until after Do, While after Loop, Until after Loop) are valid.

Multiple choice .net
  1. a choice is made based on a Boolean condition.

  2. a block of statements is executed an unknown number of times.

  3. a block of statements is executed a known number of times.

  4. Both a and b.

  5. All of the above.

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

The For...Next loop is specifically designed when you know exactly how many iterations are needed in advance. It uses a counter that increments automatically from a starting value to an ending value. This makes it ideal for processing arrays or executing code a predetermined number of times.

Multiple choice .net
  1. is used to prevent infinite loops.

  2. must be a negative value.

  3. signals the end of a list of data.

  4. Both a and b.

  5. All of the above.

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

A sentinel value is a special value chosen to indicate the end of a data stream - it's not part of the actual data, just a signal. For example, using -999 or 999 to mark that there are no more valid test scores to process. It can be any value outside the normal data range, not necessarily negative.

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-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. 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. 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. 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.

Multiple choice .net
  1. It prevents a procedure from being self contained.

  2. It makes it easier to document the code.

  3. Local variable names can be reused in other procedures.

  4. Both a and b.

  5. All of the above.

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

Module variables break encapsulation by making procedures dependent on external state rather than being self-contained units. This complicates documentation since the variable's usage spans multiple procedures, and it prevents local variable name reuse within individual procedures. All three are valid reasons to avoid module-level variables.

Multiple choice .net
  1. the length of the variable.

  2. the name of the variable.

  3. the accessibility of the variable.

  4. the datatype of the variable.

  5. the lifetime of the variable.

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

To answer this question, the user needs to have knowledge of programming concepts, specifically the concept of variable scope.

The scope of a variable refers to the accessibility or visibility of the variable within a program. It determines where and how the variable can be accessed and used.

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

A. the length of the variable: This option is incorrect. The scope of a variable is not related to its length. The length of a variable may refer to the number of characters or bytes used to store its value, but that is not the same as its scope.

B. the name of the variable: This option is incorrect. The scope of a variable is not determined by its name. While the name of a variable is important for identifying and referencing it, it does not define its scope.

C. the accessibility of the variable: This option is correct. The scope of a variable refers to its accessibility within a program. It determines where and how the variable can be accessed and used. The accessibility of a variable can be influenced by factors such as its declaration location and the programming language being used.

D. the datatype of the variable: This option is incorrect. The scope of a variable is not related to its data type. The data type of a variable determines the type of values it can store, but it does not define its scope.

E. the lifetime of the variable: This option is incorrect. The scope of a variable and its lifetime are related concepts but not the same. The lifetime of a variable refers to the period during which the variable exists in memory, whereas the scope refers to where and how the variable can be accessed within a program.

The Answer is: C. the accessibility of the variable.