C++ pass by value

Created By: chatGPT

Pass by Value is a method of passing arguments to functions in C++. When you pass by value, a copy of the original variable is made, and any changes made inside the function do not affect the original variable. This is useful when you want to ensure that the original data remains unchanged. Here's an example of how it works:
#include <iostream>

void modifyValue(int num) {
    num += 10; // This change is not reflected outside this function
    std::cout << "Inside modifyValue: " << num << std::endl;
}

int main() {
    int originalValue = 5;
    std::cout << "Before modifyValue: " << originalValue << std::endl;
    modifyValue(originalValue);
    std::cout << "After modifyValue: " << originalValue << std::endl; // originalValue remains unchanged
    return 0;
}
In the example above, when modifyValue is called, a copy of originalValue is created. The function modifies its local copy, but the originalValue in main remains unchanged, demonstrating the concept of pass by value.This behavior is especially important for primitive types like int, char, and float. However, for complex types like arrays or classes, passing by value can lead to inefficient memory usage because of the extra overhead of copying large structures.
Introduction And SetupVariablesData TypesIntFloatDoubleCharBoolStringVoidConstantsOperatorsArithmetic OperatorsRelational OperatorsLogical OperatorsBitwise OperatorsAssignment OperatorsTernary OperatorControl FlowIf StatementElse StatementElse If StatementSwitch StatementFor LoopWhile LoopDo While LoopBreak StatementContinue StatementGoto StatementFunctionsFunction DeclarationFunction DefinitionFunction OverloadingInline FunctionsDefault ArgumentsRecursionPass By ValuePass By ReferenceData StructuresArraysMultidimensional ArraysStructsEnumsUnionsClassesObjectsMember FunctionsConstructorsDestructorsAccess SpecifiersPublicPrivateProtectedInheritancePolymorphismFunction OverridingVirtual FunctionsPure Virtual FunctionsOperator OverloadingTemplatesNamespaceCommentsSingle Line CommentsMulti Line CommentsSyntaxSemicolonCurly BracesParenthesesEvent HandlingCinCoutError HandlingTry BlockCatch BlockThrow StatementException HandlingPreprocessor DirectivesInclude GuardsMacro DefinitionsInline AssemblyStatic KeywordsExtern KeywordsConst KeywordsVolatile KeywordsFriend FunctionStatic MemberThis PointerDynamic Memory AllocationNew OperatorDelete Operator