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 java
  1. Yes

  2. No

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

A 'for' statement can loop indefinitely if the termination condition is never met or is omitted entirely. For example, 'for(;;)' is a standard idiom in Java and C-style languages to create an infinite loop that must be exited via a break or return statement.

Multiple choice java
  1. Float

  2. None of the above

  3. byte

  4. String

  5. integer

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

In Java, 'byte' is a primitive type. 'String' is a class (reference type). 'integer' is not a valid keyword (it's 'Integer' wrapper or 'int' primitive). 'Float' is a wrapper class (primitive is 'float'). Therefore, 'byte' is the only primitive type listed.

Multiple choice .net
  1. the system.

  2. a user’s action.

  3. the program itself.

  4. Both a and b.

  5. All of the above.

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

Events in modern programming can be triggered by user interactions (clicks), the operating system (timers, system messages), or the program's own logic (triggering custom events). Thus, all these sources can generate events.

Multiple choice .net
  1. Const Form As Integer

  2. Const myForm As Integer

  3. Dim Form As Integer

  4. Dim myForm As Integer

  5. All of the above.

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

Both Const (for constants) and Dim (for variables) are valid statements for declaring entities. The naming rules are the same for both - 'Form' is a reserved keyword but 'myForm' is not, making B and D valid. Therefore all declarations shown are syntactically correct.

Multiple choice .net
  1. a variable.

  2. an object property.

  3. an expression.

  4. Both a and b.

  5. All of the above.

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

In programming, an assignment statement is used to assign a value to a variable or object property. The value on the right side of the assignment statement is typically an expression, which can be a combination of literals, variables, and operators that evaluates to a value.

Option A) A variable - This option is incorrect because a variable is typically on the left side of an assignment statement, indicating where the value will be stored.

Option B) An object property - This option is incorrect because the right side of an assignment statement typically holds the value that will be assigned to the object property.

Option C) An expression - This option is correct because an expression is a valid value that can be assigned to a variable or object property.

Option D) Both a and b - This option is incorrect because a variable is typically on the left side of an assignment statement, indicating where the value will be stored, while an object property is typically on the left side of a property assignment statement.

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

The correct answer is option C) an expression.

Multiple choice .net
  1. It can be made of multiple values concatenated into one string.

  2. It can include the vbCrLf constant.

  3. It can include the ampersand symbol to concatenate strings.

  4. Both a and b.

  5. All of the above.

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

The correct answer is E. All of the above.

The prompt argument in VBA can be made of multiple values concatenated into one string. For example, the following code will display a prompt that says "Enter your name and age:":

prompt = "Enter your name and age:" & vbCrLf & "Name: " & _ vbTab & "Age: "

The prompt argument can also include the vbCrLf constant, which represents a carriage return and line feed. This will cause the prompt to be displayed on two separate lines.

Finally, the prompt argument can include the ampersand symbol to concatenate strings. For example, the following code will display a prompt that says "Your name is: [name]":

prompt = "Your name is: "& name

Therefore, all of the options A, B, and C are true about the prompt argument.

Here is a breakdown of the options:

  • Option A: The prompt argument can be made of multiple values concatenated into one string. This is true because the prompt argument is a string, and you can concatenate strings together using the ampersand symbol.
  • Option B: The prompt argument can include the vbCrLf constant. This is true because the vbCrLf constant represents a carriage return and line feed, and you can include any character or string in the prompt argument.
  • Option C: The prompt argument can include the ampersand symbol to concatenate strings. This is true because the ampersand symbol is used to concatenate strings together, and you can use it in the prompt argument.

Therefore, the correct answer is E. All of the above.

Multiple choice .net
  1. use the Val function to convert the Text value.

  2. use the CDbl function to convert the Text value.

  3. use the IsNumeric function to convert the Text value.

  4. Both a and b.

  5. All of the above.

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

To process a number typed in a TextBox, the programmer must convert the Text value to a numeric data type. This is necessary because the Text property of a TextBox control returns a string value, which cannot be used in mathematical operations without first being converted.

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

A. use the Val function to convert the Text value: This option is partially correct. The Val function is one way to convert a string to a numeric data type, but it is not the only way. The Val function converts a string to a Double data type, so it may not be appropriate if the value in the TextBox is an Integer.

B. use the CDbl function to convert the Text value: This option is partially correct. The CDbl function is another way to convert a string to a numeric data type, but it is not the only way. The CDbl function converts a string to a Double data type, so it may not be appropriate if the value in the TextBox is an Integer.

C. use the IsNumeric function to convert the Text value: This option is incorrect. The IsNumeric function does not convert a string to a numeric data type. Instead, it checks whether a value is numeric and returns a Boolean value.

D. Both a and b: This option is correct. Using either the Val or CDbl function can convert a string to a numeric data type. However, the programmer should choose the appropriate function depending on the data type of the value in the TextBox.

E. All of the above: This option is incorrect. While options A and B are correct, option C is not a valid way to convert a string to a numeric data type.

Therefore, the answer is: D. Both a and b.

Multiple choice .net
  1. in all If...Then statements.

  2. in all Multi-line statements with Else.

  3. in Single Line statements.

  4. Both a and b.

  5. All of the above.

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

The End If statement is required to close multi-line If blocks, especially when they include an Else clause. Single-line If statements (If condition Then statement) don't require End If. Option B correctly identifies this requirement.

Multiple choice .net
  1. If...Then

  2. Select Case

  3. Do...Loop

  4. For...Next

  5. All of the above.

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

To solve this question, the user needs to be familiar with the different types of selection structures in programming and their characteristics.

A. If...Then is a type of selection process that uses a single expression to determine which branch to take. This expression can be a Boolean expression, a variable, or a comparison operator. However, If...Then does not involve multiple branches from a single expression.

B. Select Case is a type of selection process that allows multiple branches from a single expression. Depending on the value of the expression, the program will execute the corresponding case statement. This allows for more efficient and organized code when dealing with multiple possible outcomes.

C. Do...Loop is a type of iteration process that allows a block of code to be executed repeatedly until a certain condition is met. It does not involve multiple branches from a single expression.

D. For...Next is a type of iteration process that allows a block of code to be executed for a specific number of times. It does not involve multiple branches from a single expression.

E. All of the above options describe different types of selection and iteration processes in programming, but only option B, Select Case, is an example of a selection process that involves multiple branches from a single expression.

Therefore, the correct answer is: The Answer is B.

Multiple choice .net
  1. The corresponding block of statements is run.

  2. The next Case test value is checked.

  3. The Case Else statement is run.

  4. The Select Case construct is exited.

  5. An error is generated.

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

To solve this question, the user needs to have an understanding of the Select Case construct in programming and how it works.

The Select Case construct is a decision-making structure in programming that allows a program to execute different sections of code based on the value of a test expression. The test expression is compared to each case expression, and if a match is found, the corresponding block of statements under that case is executed.

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

A. The corresponding block of statements is run: This option is correct. When a test value matches the test expression in a Select Case construct, the corresponding block of statements under that case is executed.

B. The next Case test value is checked: This option is incorrect. Once a test value matches the test expression in a Select Case construct, the program does not check the next case test value. It executes the corresponding block of statements and exits the Select Case construct.

C. The Case Else statement is run: This option is incorrect. The Case Else statement is only executed if none of the case expressions match the test value.

D. The Select Case construct is exited: This option is incorrect. The Select Case construct is not automatically exited when a test value matches the test expression. It continues to execute the corresponding block of statements for that case.

E. An error is generated: This option is incorrect. When a test value matches the test expression, it is a valid and expected behavior in a Select Case construct. No error is generated in this scenario.

Therefore, the correct answer is:

A. The corresponding block of statements is run

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

  2. Exit For

  3. Exit Form

  4. Exit Select

  5. Exit Sub

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

To solve this question, the user needs to be familiar with programming and the concept of exit statements. Exit statements are used to prematurely terminate loops, functions, or procedures in a program.

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

A. Exit Do: This option is a valid exit statement in some programming languages, such as Visual Basic. It is used to exit a Do loop.

B. Exit For: This option is a valid exit statement in some programming languages, such as Visual Basic. It is used to exit a For loop.

C. Exit Form: This option is not a valid exit statement. "Form" is typically a term used in graphical user interface (GUI) programming to refer to a window or a user interface element. There is no standard "Exit Form" statement in most programming languages.

D. Exit Select: This option is a valid exit statement in some programming languages, such as Visual Basic. It is used to exit a Select Case or Switch statement.

E. Exit Sub: This option is a valid exit statement in some programming languages, such as Visual Basic. It is used to exit a Subroutine or Function.

Therefore, the correct answer is:

The Answer is: C. Exit Form

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.