What are local variables in C++?

C++ProgrammingObject Oriented Programming

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
raja
Updated on 11-Feb-2020 09:55:53

Advertisements