C++ Introduction Flashcards
(11 cards)
What was the first object-oriented language, and who developed it?
Simula, developed in 1964
Created by Ole-Johan Dahl and Kristen Nygaard
Developed at the Norwegian Computing Center in Oslo
Introduced key OOP concepts:
- Objects
- Classes
- Inheritance and subclasses
How did C++ originate?
Initially called “C with Classes”
Developed by Bjarne Stroustrup at Bell Labs
Started in October 1979 with a preprocessor called Cpre
Aimed to add Simula-like classes to C
First real project and library implemented by March 1980
What is a precompiler, and how does it work?
Takes source code with additional markup/functionality
Transforms the code into standard language code
Processes special directives or extensions before actual compilation
Example: Oracle Pro*C for SQL integration
Allows extending the base language’s capabilities
What key features does C++ add to C?
Classes and object-oriented programming
Exception handling
Function and operator overloading
Default parameter values
Pass by reference
Implicit casting changes
More type-safe compared to C
How do you compile and link a C++ program?
Compilation:
- Use g++ instead of gcc
- Specify C++ standard (e.g., -std=c++11)
- Typical command:
g++ -std=c++11 -c myProgram.cpp -o myProgram.o
Linking:
- Use g++ to link object files
- Typical command:
g++ myProgram.o -o myProgram
What are the major C++ standards?
C++98: First ISO standard
C++03: Minor update
C++11: Significant update, widely supported
C++14: Incremental improvements
C++17: More modern features
C++20: Latest major standard
C++23: Emerging standard, not yet widely supported
What are the key differences between cout and cerr?
cout (Console Output):
- Writes to standard output (stdout)
- Uses «_space;operator for stream insertion
- Does not automatically flush buffer
cerr (Console Error):
- Writes to standard error (stderr)
- Typically used for error messages
- Automatically flushes buffer
- Always prints immediately
What is function overloading in C++?
Allows multiple functions with the same name
Functions must differ in:
- Number of parameters
- Types of parameters
Can have different return types
Enables more intuitive function naming
Compiler determines which function to call based on arguments
What are the access specifiers in a C++ class?
private (default):
- Only accessible within the class
- Most restrictive access level
public:
- Accessible from anywhere in the program
- Defines the class’s interface
protected:
- Accessible within the class and its inheritors
- Used for inheritance-based access control
What are constructors and destructors in C++?
Constructors:
- Special member function called when object is created
- Has the same name as the class
- Used to initialize object’s state
- Can be overloaded
Destructors:
- Special member function called when object is destroyed
- Prefixed with ~ (tilde)
- Cleans up resources used by the object
- Only one destructor per class
How does a basic C++ Hello World program differ from C?
C Approach:
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}</stdio.h>
C++ Approach:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}</iostream>
Uses iostream instead of stdio
Uses cout/endl for output
Can use using namespace std to simplify syntax