0% found this document useful (0 votes)
9 views3 pages

Unit 4 5

The document provides an overview of key concepts in Object-Oriented System Design with C++, including namespaces, identifiers, constants, variables, keywords, typecasting, call by value/reference, inline functions, and macros. It outlines the rules and usage of identifiers, constants, and variables, as well as the differences between call by value and call by reference. Additionally, it discusses the benefits of inline functions and macros in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Unit 4 5

The document provides an overview of key concepts in Object-Oriented System Design with C++, including namespaces, identifiers, constants, variables, keywords, typecasting, call by value/reference, inline functions, and macros. It outlines the rules and usage of identifiers, constants, and variables, as well as the differences between call by value and call by reference. Additionally, it discusses the benefits of inline functions and macros in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit-4

Object-Oriented System Design With C++


# Namespace:-
A namespace is a declarative region that provides scope to identifiers (variables, functions, classes, etc.). It helps
avoid name conflicts, especially when working with large projects or multiple libraries.

Key Points:
1. The std namespace is commonly used (e.g., std::cout for standard output).
2. You can bring a namespace into scope using:
o using namespace myNamespace; (all members).
o using myNamespace::myVariable; (specific member).

# Identifiers:-
An identifier is the name used to identify variables, functions, arrays, or other user-defined elements.
Rules for identifiers:
1. Must begin with a letter or an underscore (_).
2. Can contain letters, digits, and underscores.
3. Cannot use reserved keywords (e.g., int, class, return).
4. Case-sensitive (e.g., myVar and MyVar are different).
# Constants:-
A constant is a value. that doesn’t change during the program’s execution.
Declared using:
1. The const keyword.
2. The constexpr keyword for compile-time constants.
3. Enumerations.

# Variables:
A variable is used to storage the location for data. that can change during program execution.

Types of Variables:
1. Local Variables: Declared inside functions or blocks.
2. Global Variables: Declared outside all functions.
3. Static Variables: Retain their value between function calls (static keyword).
4. Dynamic Variables: Allocated using new and deallocated with delete.

# keywords:-
C++ has a set of keywords. That are reserved for specific purposes and cannot be used as identifiers (names for
variables, functions, etc.). These keywords represent the core syntax and functionalities of the C++ language.

1. Data Types:- bool, char, int, float, double, void, wchar_t


2. Modifiers:- signed, unsigned, short, long
3. Control Flow:- if, else, switch, case, default
4. Loops:- for, while, do, break, continue
5. Functions: return, void
6. Access Specifiers: private, protected, public
7. Memory Management: new, delete
8. Exception Handling: try, catch, throw

Written By:- Munesh Kumnar (Pursuing B.tech (CSE)


9. Class and Object-Oriented Programming: class, struct, union, this, virtual, friend, mutable, explicit, inline
Private, protected, public, operator, static_cast, dynamic_cast, const_cast, reinterpret_cast
10. Namespace and Scope: namespace, using, extern, static
11. Constants and Modifiers: const, constexpr, volatile
12. Type Information: typeid, typename, sizeof
13. Miscellaneous: asm, auto, enum, register, goto, static_asser
14. Newer C++ (C++11 and Later): nullptr, decltype, constexpr, noexcept, override, final, thread_local, alignof,
alignas, char16_t, char32_t

# Typecasting:-
Typecasting in C++ is the process of converting a variable from one data type to another.

1. Implicit Typecasting (Type Coercion): It is Done automatically by the compiler. when it is converting a
smaller data type to a larger one (e.g., int to float). It is also called type promotion.
2. Explicit Typecasting (Type Conversion): It is used to performed manually by the programmer.
Two approaches:
a. C-Style Cast
b. C++ Cast Operators
3. Static_cast: It is used to for standard type conversions. It is also used to ensures compatibility between types
during compile time.
4. Dynamic_cast: It is used to safely cast pointers/references between base and derived classes (requires
polymorphism). It is used to performs runtime checks.

# Call by value:-
1. A copy of the value is passed into the function.
2. Changes made inside the function are limited.
3. The value of the actual parameter do not change by changing the formal parameter.
4. Actual and formal argument are created at the different memory location.
{
Int t=a;
A=b;
B=t;
}

# Call by reference:-
1. An address of value is passed into the function.
2. Changes made inside the function are not limited.
3. The value of the actual parameter do change by changing the formal parameter.
4. Actual and formal arguments are created at the same memory location.
{
If(x>y)
Return x;
Else
Return y;
}

Written By:- Munesh Kumnar (Pursuing B.tech (CSE)


# Inline Functions:-
1. An inline function is a function. That is defined with the inline keyword.
2. In the case of inline function, the program can be easily debugged.
3. Inline is not widely used as macros.
4. Inline is not used in competitive progmamming.
5. Inline function is terminated by the curly brace ath the end.
Benefits of Inline Functions:
1. Performance: Reduces the function call overhead by directly inserting the function code in place of the call.
2. Type Safety: Inline functions are type-checked, and you can use them with C++ features like overloading and
default arguments.
3. Debugging: It is easier to debug. Inline functions are actual functions.
inline return_type function_name(parameters) {
// function body
}

# Macros:-
1. A macro in C++ is a preprocessor. It is defined using #define.
2. Macros are simple text replacements.
3. Macros is widely used.
4. Macros is very much used in competitive programming.
5. It is terminated by new line.
Benefits of Macros:
1. Performance: Like inline functions, macros can avoid function call.
2. Flexibility: Macros can represent code. That isn’t possible with functions (like conditional code inclusion).
#define MACRO_NAME replacement_code

Written By:- Munesh Kumnar (Pursuing B.tech (CSE)

You might also like