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

  2. iomanip.h

  3. console.h

  4. conio.h

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

The setprecision manipulator in C++ is used to set the precision for floating-point output operations. It requires the header file (or iomanip.h in older C++ style). The iostream header provides basic input/output functionality, while iomanip specifically provides I/O manipulators like setprecision, setw, setfill, etc.

Multiple choice technology programming languages
  1. static variables

  2. register variables

  3. global variables

  4. None of the Above

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

In C++, external variables (declared with extern keyword) are also called global variables because they have global scope and can be accessed across multiple source files. Static variables have file scope only, register variables are storage class specifiers for CPU register allocation, so they are different concepts from external variables.

Multiple choice technology programming languages
  1. It resembles the header Of the function definition

  2. It tells the compiler the Names of the parameters

  3. It must be declared before its corresponding functions can be utilized

  4. All the above are incorrect

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

Function prototypes must be declared before the corresponding functions can be used in the code. This allows the compiler to perform type checking on function calls. A prototype does resemble the function header (option A is partially correct but not complete), and it does tell the compiler parameter types but typically not names (option B is incorrect). Option C correctly states the essential purpose - declaration before usage.

Multiple choice technology programming languages
  1. call by value

  2. call by reference

  3. call by address

  4. All the Above

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

Using pointers to pass arguments to a function allows the function to access and modify the original variables through their memory addresses. This technique is called call by reference. Call by value creates a copy, and call by address is not standard terminology - call by reference and call by address mean essentially the same thing.

Multiple choice technology programming languages
  1. True

  2. False

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

This declaration is incorrect because struct date contains a member 'year' of type 'date', which would create infinite recursion. A struct cannot contain a member of its own type (only pointers to itself are allowed).

Multiple choice technology programming languages
  1. Inline functions

  2. virtual functions

  3. Both A and B

  4. None of the Above

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

Inline functions are expanded at the call site, meaning the function body code is inserted directly where called rather than using a function call mechanism. This is done to eliminate function call overhead.

Multiple choice technology programming languages
  1. It resembles the header Of the function definition

  2. It tells the compiler the Names of the parameters

  3. It must be declared before its corresponding functions can be utilized

  4. All the above are incorrect

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

A function prototype informs the compiler about the function's interface (return type, parameters) so it can be verified before the full function definition is encountered. Since it declares the function, it must be declared before any utilization. Other options are correct descriptors of prototypes, making the choice of only one valid option slightly ambiguous, but the marked option is technically true.

Multiple choice technology programming languages
  1. Syntax Error

  2. Linker Error

  3. Runtme Error

  4. No Error, It will be run successfully

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

The code declares a function prototype int GetSquareOfx(int) but never provides the function definition. When the linker tries to resolve the function call GetSquareOfx(), it fails because the definition is missing. This produces a linker error (undefined reference), not a syntax error (which would be caught during compilation).

Multiple choice technology programming languages
  1. const

  2. volatile

  3. mutable

  4. All the Above

  5. None of the Above

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

const, volatile, and mutable are all storage qualifiers (cv-qualifiers) in C++. const indicates the value cannot be modified, volatile tells the compiler the value may change in ways not visible to the compiler (prevents optimization), and mutable allows a member variable to be modified even in a const member function.

Multiple choice technology programming languages
  1. static variables

  2. register variables

  3. global variables

  4. None of the Above

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

External variables in C++ are variables declared outside any function, making them accessible across multiple source files. These are commonly called global variables. Static variables have internal linkage (visible only within the file), and register variables are a hint to store variables in CPU registers (mostly obsolete in modern compilers).

Multiple choice technology programming languages
  1. True

  2. False

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

The struct contains a member 'date year' of its own type 'struct date', which creates a circular definition. C structs cannot contain members of their own type directly (only pointers). This would cause compilation error.