The variable declared inside function is called local variable in C++
Example #include<iostream.h> void main() { int x; int Y; int Z; Cout << X << endl; cout<<Z<<endl; } o/p : The output of above program is garbage value, Because local variables are not given any default values.
Example # include <iostream.h> void main() { int n1; cout<< “\n input n1 value”; cin >> n1; int n2; cout<< “\n input n2 value”; cin>> n2; int n3; n3=n1+n2; cout<< “\n sum is ” << n3 } os void main() {
The variables which are declared inside the anyone of the following block is called as Block level variables in C++
Example if(<condition>) { int x; - > block level } Conditional Block while(<condition>) { int y; Block level } Iterational block Example # include <iostream.h void main() { char name[10]; int sub1,sub2; cout<<”\n input name”; cin>> name; cout<< “\n input two subjects”; cin>> sub1 >> sub2; cout<< “\n input two subjects”; cin>> sub 1>> sub 2; cout << “\n name” << name; if(sub1>=40 && sub2 >=40) { int total = sub1+sub2; flat avg=total/3; cout<<”\n Total” << total; cout<< “\n Avg” << avg; cout<< “\n Result is pass”; } else cout<< “\n result fail” }
void main () { int x=10; int y=20; cout<<”\n local variable x=”<<x 10 cout<<”\n local variable y=”<<y; 20 { int z=30; cout<< “\n Block local variable z=” <<Z; 30 int x=40; cout<<”\n Block local variable=” <<x; cout<<”\n block variable y= <<y”; } }
Syntax : int x; - > global variable void main() { int y; - > local variable if(<condition>) { int z; block level variable }
3 *(pointer to pointer member access operator)
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.