C++ Introduction Flashcards

(11 cards)

1
Q

What was the first object-oriented language, and who developed it?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How did C++ originate?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a precompiler, and how does it work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What key features does C++ add to C?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you compile and link a C++ program?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the major C++ standards?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the key differences between cout and cerr?

A

cout (Console Output):
- Writes to standard output (stdout)
- Uses &laquo_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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is function overloading in C++?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the access specifiers in a C++ class?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are constructors and destructors in C++?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does a basic C++ Hello World program differ from C?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly