Wk2-6 Content Flashcards
What is the primary focus of procedural programming?
Focusing on a specific aim or end result with limited reusability.
How do procedures (or functions) in procedural programming relate to the main() function?
They are declared/defined independent of main() and called within the program.
What is the main() function in C++ compared to Java?
In C++, main() is a standalone function that returns an int, whereas in Java, it is a static public member of a Runnable class.
What does the return value of 0 typically indicate in a C++ program?
It typically means a normal termination of the program.
Describe the basic structure of a C++ ‘Hello World!’ program.
The program includes function arguments, a return_type, and outputs ‘Hello World!’.
What is the role of #include in C++?
It brings in a header, like iostream, effectively a collection of code written elsewhere.
How do input/output streams work in C++?
Using cin for input and cout for output, with operators like «_space;for insertion.
Explain the difference between literals and variables in C++ output.
Literals have fixed explicit values, whereas variables do not.
What is the significance of using namespace std in C++?
It allows for shorter syntax but can lead to name collisions.
How is scope defined in C++ and what is its importance?
Scope is the context where a variable is visible and is defined by braces {}.
What does the term ‘global scope’ mean in C++?
A variable or entity is visible anywhere in the file after its declaration.
Can main() in C++ have arguments? If yes, what are they?
Yes, int main(int argc, char *argv[]) where argc is the argument count and argv is an array of arguments.
What is the purpose of the stoi function in C++?
It is used to convert strings to integers.
What is a forward declaration in C++?
Declaring a function before defining it, typically before reaching main().
Why is it advantageous to spread code across multiple files in C++?
It helps in organizing code, reusing functions, and easing debugging.
What is the purpose of header (.h) files in C++?
To declare data structures and function prototypes for use in other files.
How does the C++ library cmath enhance programming capabilities?
It provides access to mathematical functions, like square root.
Is it necessary to include a return statement in C++ functions?
While it can be omitted, it is best practice to include it for clarity.
What are the advantages of using functions in procedural programming?
Code reusability, ease of maintenance, and improved program structure.
What is the difference between signed and unsigned types in C++?
Signed types can represent both positive and negative values, while unsigned types represent only non-negative values.
How is the input/output functionality implemented in C++?
Through iostream library, using cin for input and cout for output.
What is the role of endl in C++?
It is a manipulator used to insert a newline character and flush the output buffer.
What does the term ‘unstructured code’ refer to in C++?
Code written without using functions or procedures, often in a sequential manner.
How does the concept of namespaces improve code organization in C++?
Namespaces prevent name collisions and organize code into logical groups.