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

Live Demo

#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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 11-Feb-2020

281 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements