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 technology programming languages
  1. sizeof

  2. ::

  3. :?

  4. All the Above

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

C++ prohibits overloading the sizeof operator (language built-in for memory size), scope resolution operator :: (fundamental to language syntax), and ternary operator ?: (conditional operator has special syntax rules). These operators are part of the core language and their behavior is fixed by the specification.

Multiple choice technology programming languages
  1. zero

  2. NULL

  3. one

  4. No Entry in vtable

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

Compilers typically set the vtable entry for a pure virtual function to NULL. This ensures that attempting to call a pure virtual function directly (without overriding) results in a predictable error. The NULL entry indicates no implementation is available in this class. Abstract classes cannot be instantiated precisely because they have such NULL vtable entries.

Multiple choice technology programming languages
  1. No default constructor is provided by the compiler

  2. The compiler provides the default constructor

  3. The compiler generates error

  4. None of the Above

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

In the given code, a class named "exforsys" is defined. It does not have any member variables or functions.

Now, let's go through each option and determine which one is true:

A. No default constructor is provided by the compiler: This option is incorrect. By default, if no constructor is defined in a class, the compiler provides a default constructor. So, this option is false.

B. The compiler provides the default constructor: This option is correct. When no constructor is defined in a class, the compiler automatically generates a default constructor. So, this option is true.

C. The compiler generates an error: This option is incorrect. Since the class does not have any member variables or functions, there is no reason for the compiler to generate an error. So, this option is false.

D. None of the above: This option is incorrect. As explained earlier, the correct answer is option B. So, this option is false.

Therefore, the correct answer is:

B. The compiler provides the default constructor.

Multiple choice technology programming languages
  1. Private members of the class

  2. protected members of the class

  3. Both A and B

  4. None of the Above

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

Friend functions in C++ are granted special access to the private and protected members of the class they befriend. This breaks normal encapsulation rules when needed. Friend functions are commonly used for operator overloading and when external functions need deep class access. They do not access public members differently than any other function.

Multiple choice technology databases
  1. NVL

  2. NULLIF

  3. DECODE

  4. COALESCE

Reveal answer Fill a bubble to check yourself
A,B,D Correct answer
Explanation

NVL, NULLIF, and COALESCE are standard SQL functions designed specifically to handle NULL values. While DECODE can handle NULLs in its logic, it is primarily a conditional transformation function rather than a dedicated NULL-handling function like the others.

Multiple choice technology programming languages
  1. Write Once, Run Anywhere

  2. Read Once, Write Anywhere

  3. Read Once, Run Anywhere

  4. Write Twice, Run Once

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

Java's core promise is 'Write Once, Run Anywhere' (WORA), enabled by the Java Virtual Machine (JVM). This means compiled Java code can run on any platform supporting JVM without recompilation. The other options are incorrect.

Multiple choice technology programming languages
  1. Compilation Error - Struct cannot be defined without a name

  2. 193149

  3. Compilation Error - Struct cannot be defined inside a Function

  4. Some Random Number

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

In C, you can define an anonymous structure and instantiate it immediately (struct { ... } var;). This is valid inside a function, and the code will print the assigned integer value 193149.

Multiple choice technology databases
  1. Header

  2. Declarative

  3. Executable

  4. Exception

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

PL/SQL blocks have four sections: Header (optional, for named blocks), Declarative (DECLARE section for variables, types, cursors), Executable (BEGIN...END for main logic), and Exception (EXCEPTION section for error trapping and handling). The Exception section specifically contains functions and handlers for errors.

Multiple choice technology databases
  1. TRUE

  2. FALSE

  3. Undefined

  4. NULL

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

In SQL, NULL represents an unknown value. When two NULL values are compared using operators like =, <>, >, <, etc., the result is NULL (unknown), not TRUE or FALSE. This is because NULL is not a value but a marker for missing information, so comparing two unknowns yields an unknown result.

Multiple choice technology programming languages
  1. True

  2. False

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

The statement is false. Java's arithmetic type promotion rules are more nuanced than simply taking the 'widest' type. For binary operations, Java uses 'widening primitive conversion' which promotes smaller types to int or long specifically, not just to the widest operand. For example, byte + byte produces int, not byte. char + byte produces int. Only if both operands are at least int does the result type become the wider of the two. The rule is: if either operand is double, result is double; else if float, result is float; else if long, result is long; otherwise, result is int.

Multiple choice technology
  1. -1

  2. 0

  3. 1

  4. -1/1

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

For a REPEAT operation in webMethods FLOW to execute continuously as long as the condition remains true (indefinite loop), the count parameter must be set to -1. A count of 0 means no iterations, while 1 means exactly one iteration. The option '-1/1' is not a valid count value.

Multiple choice technology programming languages
  1. Stack

  2. Heap

  3. Code Segment

  4. Data Segment

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

In C, the malloc() function allocates memory dynamically on the heap. The statement 'char *ptr = malloc(10);' allocates 10 bytes on the heap and stores the address in pointer ptr (which itself is on the stack). The stack is used for local variables, code segment for instructions, and data segment for static/global variables.

Multiple choice technology programming languages
  1. Heap

  2. Stack

  3. Code Segment

  4. Data Segment

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

Static variables in C are stored in the data segment (specifically, the .data or .bss section depending on initialization). Unlike local variables which are on the stack, static variables retain their value across function calls and are allocated when the program starts, persisting for the entire program duration. Heap is for dynamic allocation (malloc/free) and code segment stores executable instructions.