C++ variable scope


  Translation results:

C++ is a statically typed, compiled, general-purpose, case-sensitive, irregular programming language that supports procedural programming, object-oriented programming and generic programming.

C++ is considered a mid-level language that combines the features of high-level and low-level languages.

C++ was designed and developed by Bjarne Stroustrup in 1979 at Bell Laboratories in Murray Hill, New Jersey. C++ further extended and improved the C language, originally named C with classes and later renamed C++ in 1983.

C++ is a superset of C. In fact, any legal C program is a legal C++ program.

C++ variable scopesyntax

Scope is an area of ​​the program. Generally speaking, there are three places where variables can be defined:

Variables declared inside a function or a code block are called local variables.

Variables declared in the definition of function parameters are called formal parameters.

Variables declared outside all functions are called global variables.

C++ variable scopeexample

#include <iostream>
using namespace std;
int main (){
// Local variable declaration
int a, b; int c;
// Actual initialization
a = 10; b = 20; c = a + b;
cout << c;
return 0;}

Home

Videos

Q&A