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 php
  1. function myFunction()

  2. new_function myFunction()

  3. create myFunction()

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

PHP uses the function keyword to declare a user-defined function, followed by the function name and parentheses. Keywords like new_function or create are not valid PHP syntax for declaring functions. This follows standard C-style and scripting language conventions used in PHP.

Multiple choice php
  1. $my-Var
  2. $myVar
  3. $my_Var
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To determine which variable has an illegal name, we need to understand the rules for variable naming conventions.

In most programming languages, variables can be named using letters, numbers, and underscores. However, there are some restrictions:

  1. The variable name cannot start with a number.
  2. The variable name cannot contain spaces or special characters, except for underscores.

Now let's analyze each option:

A. $my-Var: This variable name uses a hyphen (-) between "my" and "Var". Hyphens are not allowed in variable names in most programming languages, so option A has an illegal name.

B. $myVar: This variable name uses only letters and does not contain any illegal characters. Option B has a legal name.

C. $my_Var: This variable name uses an underscore (_) between "my" and "Var". Underscores are commonly used in variable names and are allowed in most programming languages. Option C has a legal name.

Therefore, the variable with the illegal name is:

The Answer is: A. $my-Var

Multiple choice php
  1. Ends execution of the current switch structure

  2. Moves on to the next iteration of the current for, foreach, while, do-while or switch structure

  3. Ends execution of the current for, foreach, while, do-while or switch structure

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

The break statement is used to immediately terminate the execution of the current loop (for, foreach, while, do-while) or switch structure. Option 4424 is too narrow as it only mentions switch, and 4425 describes the continue statement, which skips to the next iteration rather than ending the structure.

Multiple choice .net vb
  1. One

  2. Two

  3. Three

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

.NET Framework has two compilation levels: first, source code compiles to Intermediate Language (IL) by language compilers (C#/VB.NET); second, IL compiles to native machine code by the Just-In-Time (JIT) compiler at runtime.

Multiple choice .net vb
  1. Specifies that any variable name is declared (with type) before use

  2. Specifies whether strings should be compared as binary

  3. Specifies that variables should be initialized before use

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

Option Explicit On requires that all variables be declared before use. This prevents undeclared variables (often from typos) from being created implicitly, catching naming errors at compile time rather than runtime.

Multiple choice .net vb
  1. Exit

  2. Close Sub

  3. Exit Sub

  4. Kill

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

To terminate code execution within a VB.NET method, you can use the "Exit Sub" statement.

Explanation of options:

A. Exit: The "Exit" keyword is used to exit a loop or block of code, but it cannot be used to terminate a method. It is not the correct option in this scenario.

B. Close Sub: This is not a valid statement in VB.NET. It is not the correct option.

C. Exit Sub: The "Exit Sub" statement is used to immediately exit from a subroutine (method) in VB.NET. It allows you to terminate the execution of the method and return control to the calling code. This is the correct option.

D. Kill: The "Kill" statement is used to delete a file in VB.NET and is not related to terminating code execution within a method. It is not the correct option.

Therefore, the correct answer is: C. Exit Sub

Multiple choice .net vb
  1. Using Only Get..EndGet with in property definition

  2. Using Only Set..EndSet with in property definition

  3. Using both Get and Set

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

In VB.NET, a read-only property is created by including only the Get accessor without a Set accessor. This allows the property value to be read but not modified from outside the class. Option B (only Set) would create a write-only property, while option C (both Get and Set) creates a read-write property.

Multiple choice java
  1. Vptr

  2. Void

  3. Null

  4. Zero

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

A null pointer is a special pointer value that points to no memory location and is typically represented as zero. Void pointers can point to any data type but are not necessarily null. The question describes a null pointer, which can be assigned to any pointer type and conventionally has the value zero.

Multiple choice java
  1. Virtual functions

  2. Inline functions

  3. Static functions

  4. Friend functions

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

Inline functions are expanded at compile time - the function call is replaced by the actual function code, eliminating function call overhead. This is a compiler optimization that trades code size for execution speed. Virtual functions use dynamic dispatch, static functions have file scope, and friend functions access private data - none of these replace the call with code at compile time.

Multiple choice typrun
  1. TYPRUN= HOLD

  2. TYPRUN= SCAN

  3. TYPRUN= SUB

  4. TYPRUN= HELD

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

TYPRUN=SCAN is used to check JCL for syntax and logic errors without executing the job. HOLD places the job in held status, SUB is not a valid parameter, and HELD is not the correct parameter name.

Multiple choice qn6
  1. Converting reference type to value type

  2. Converting value type to reference type

  3. converting int to string

  4. none

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

Boxing converts a value type (like int, float) to a reference type (object) by wrapping it in an object. This allows value types to be treated as objects when needed. The reverse process is unboxing.

Multiple choice qn7
  1. Converting reference type to value type

  2. Converting valuetype to reference type

  3. Converting int to string

  4. None

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

Unboxing extracts the value type from a reference type (object) that was previously boxed. It is the explicit conversion from object back to the original value type. Boxing/unboxing have performance implications.

Multiple choice qn8
  1. Input

  2. Return

  3. Output

  4. Extern

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

Output parameters are used in stored procedures to return values to the calling program. Input parameters pass data in, Return is for status codes, and Extern is not a parameter direction.

Multiple choice qn9
  1. String

  2. Int

  3. bool

  4. Object

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

The ExecuteScalar method of a command object returns a single value from the first row of the result set returned by the query. The data type of the returned value depends on the type of the column being retrieved.

In this case, the options provided are:

A. String: This option is incorrect because the ExecuteScalar method does not always return a string. It can return values of different data types, depending on the column being retrieved.

B. Int: This option is incorrect because, similar to option A, the ExecuteScalar method does not always return an integer. It can return values of different data types.

C. bool: This option is incorrect for the same reasons mentioned above. The ExecuteScalar method can return values of different data types, not just boolean values.

D. Object: This option is correct. The ExecuteScalar method returns the value as an Object data type. This allows for flexibility in handling different data types returned by the query.

Therefore, the correct answer is D.