
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What are local variables in C++?
Variables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions on their own.
Example
#include <iostream> using namespace std; int main () { int a, b; int c; a = 10; b = 20; c = a + b; cout << c; return 0; }
Output
This will give the output −
30
- Related Articles
- What are local variables and global variables in C++?
- What are class variables, instance variables and local variables in Java?
- What are Local Scope Variables in Postman?
- What are the local static variables in C language?
- What are the rules for local and global variables in Python?
- Are static local variables allowed in Java?\n
- Local variables in Java
- Member variables vs Local variables in Java
- System variables vs Local Variables in MySQL?
- User-defined variables vs Local Variables in MySQL?
- What are the modifiers allowed to use along with local variables in Java?
- Final local variables in C#
- What is the scope of local variables in Java?
- Global and Local Variables in Python?
- Global and Local Variables in Java

Advertisements