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 c
  1. Infinite loop

  2. Syntax error

  3. Depends on the compiler

  4. none of the above

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

To understand the given statement and determine the correct answer, we need to analyze the syntax and behavior of the code.

The given statement is a while loop with the condition "1". In C and C++ programming languages, any non-zero value is considered true, and the loop will continue executing as long as the condition is true.

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

A. Infinite loop: This option is correct. Since the condition "1" is always true, the loop will continue executing indefinitely, resulting in an infinite loop. The loop will not terminate unless there is a break statement or the program is interrupted externally.

B. Syntax error: This option is incorrect. The given statement does not contain any syntax errors. It is a valid while loop syntax in C and C++.

C. Depends on the compiler: This option is incorrect. The behavior of the given statement does not depend on the compiler. The program will behave in the same way regardless of the compiler being used.

D. none of the above: This option is incorrect. As explained above, the correct answer is A, as the given statement will result in an infinite loop.

The Answer is: A

Multiple choice c
  1. Perform standard functions like printing to the screen

  2. Data storage

  3. Both correct

  4. Both wrong

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

Variables are named memory locations used for data storage (B). They do not perform standard functions like printing; that is the role of functions/libraries.

Multiple choice c
  1. Must be declared before being used.

  2. Can be used without declaration

  3. Can be used before declaration

  4. none of the above

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

In C (specifically C89/90 and generally), variables must be declared before use. Modern C (C99) allows mixed declarations, but generally one cannot use a variable before it exists.

Multiple choice c
  1. Infinite loop

  2. Syntax error

  3. Executes only 3 iterations

  4. Executes only 4 iterations

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

In C, any non-zero integer is considered true. Therefore, while(3) evaluates to true, and since the loop body is empty (just a semicolon), it loops indefinitely.

Multiple choice assembly
  1. Must be defined explicitly in the program

  2. DOS uses the high area of the COM program for the Stack

  3. There is no stack for .COM program during execution

  4. none of the above

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

In the .COM file format, there is no explicit stack segment defined. Upon loading, DOS initializes the stack pointer (SP) to the very end of the 64KB segment (usually 0xFFFE). The stack grows downward from the top of the memory allocated to the program.

Multiple choice php
  1. When the parameter is Boolean

  2. When the function is being declared as a member of a class

  3. When the parameter is being declared as passed by reference

  4. When the function contains only one parameter

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

Default values for function parameters (using '= value') are syntactically valid in C++ for primitive types (like Boolean) and class methods. However, they generally cannot be used for parameters passed by reference unless the reference is to a const type (e.g., 'const int&'). As the option implies a non-const reference (standard modifiable reference), this is the circumstance where a default argument is typically invalid or nonsensical.

Multiple choice php
  1. function is_leap($year = 2000)
  2. function is_leap($year default 2000)
  3. function is_leap($year)
  4. is_leap($year default 2000)
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In PHP, default parameter values are defined using the assignment operator '=' within the function signature. 'function is_leap($year = 2000)' correctly sets the default value to 2000 if no argument is passed, satisfying the requirement for is_leap() to return true (for the year 2000).

Multiple choice php
  1. $a *= pow (2, 2);
  2. $a >>= 2;
  3. $a <<= 2;
  4. $a = $a $a;
Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

In PHP, '\$a <<= 2' shifts the bits of \$a two places to the left, which is equivalent to multiplying by 2 squared (4). The first option '\$a *= pow(2, 2)' also results in \$a * 4. Since this is a multiple-choice question with two correct options, both are valid logic.

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. public void amethod(int s, String i){}

  2. public void Amethod(int i, String s) {}

  3. public void amethod(int i, String mystring){}

  4. None of the above

  5. public int amethod(int i, String s){}

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

The question asks which method can be legally placed in the class. Option A changes only parameter names (s, i), which is invalid overloading (same signature). Option C changes a parameter name (mystring), same signature. Option E changes the return type only, which is invalid. Option B changes the method name to 'Amethod' (case sensitivity), creating a valid overloaded method.

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