C++_Concepts_Notes
C++_Concepts_Notes
OOP is a programming paradigm based on the concept of "objects", which contain data and methods to
operate on that data. It allows data and functions to be bundled together, promoting modularity, code
class Car {
public:
string brand;
void start() {
};
Object-Based Programming:
Object-based programming also uses objects but does not support all OOP principles like inheritance and
Differences:
----------------------------------------------------------------------
Explain the following with a code snippet:
(i) Methods
(i) Methods:
Example:
class Car {
public:
string brand;
void display() {
};
Example:
class Animal {
public:
};
public:
void sound() {
};
----------------------------------------------------------------------
What is a function? How to declare and define functions in C++? Explain with examples.
Function:
Function Declaration:
Function Definition:
return a + b;
Function Call:
Example:
#include <iostream>
return a + b;
int main() {
return 0;
----------------------------------------------------------------------
Variables:
Operations:
- Arithmetic: + - * / %
- Logical: && || !
- Assignment: = += -=
Scope Resolution Operator ::
Example:
int x = 10;
int main() {
int x = 20;
----------------------------------------------------------------------
Inline Function:
A function where code is expanded at the point of call to save call overhead. Declared using `inline`.
Example:
return x * x;
Difference:
C++ Tokens:
4. Operators (+, -, =)
Reference Variables:
Example:
int a = 5;
int &ref = a;