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

  2. string

  3. Float

  4. unsigned

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

In Java, 'interface' is a reserved keyword used to define an interface, while 'unsigned' is not a keyword in Java. Option B ('string') is invalid because the correct primitive type name is 'String' (capital S) or it refers to the class java.lang.String, and Option C ('Float') refers to a wrapper class, not a keyword.

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. print() can be used as part of an expression, while echo() can't

  2. echo() can be used as part of an expression, while print() can't

  3. echo() can be used in the CLI version of PHP, while print() can't

  4. print() can be used in the CLI version of PHP, while echo() can't

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

In PHP, print() returns a value (1), allowing it to be used in expressions (e.g., if (!print('a'))). echo() does not return anything and outputs the string directly, making it invalid within complex expressions requiring a return value.

Multiple choice java
  1. Double precision floating-point (double)

  2. Character (char)

  3. Byte integer (byte)

  4. Boolean (boolean)

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

The char primitive type in Java is designed to store Unicode characters using 16-bit UTF-16 encoding. This allows Java to support international characters. Double is for floating-point numbers, byte for small integers, and boolean for true/false values.

Multiple choice java
  1. Short integer to character

  2. Integer to long integer

  3. Floating-point to double precision floating-point

  4. Character to floating-point

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

Widening conversions occur when a value is moved to a type that can accommodate its range. Short to char is not a widening conversion because short is signed (-32768 to 32767) and char is unsigned (0 to 65535); thus, negative short values cannot be represented in char.