/* C++ program to demonstrate use of local and global variable */ #include "iostream" using namespace std; int num; void myfunc(); int main(){ num = 10; cout<<"Num in main: "<<num; myfunc(); myfunc(); cout<<"\n Num at the end: "<<num; return 0; } void myfunc(){ int num=20; cout<<"\nNum: "<<num; num += 10; } /* --In case of same variable name (both local and global), reference will be always local. [pavan@localhost Practise]$ g++ LocalVariable.cpp [pavan@localhost Practise]$ ./a.out Num in main: 10 Num: 20 Num: 20 Num at the end: 10[pavan@localhost Practise]$ */
The Tech Zone is built to promote open source technologies. Hadoop, Linux Administration, Cloud, Java Technologies, Operating Systems, Advanced Computer Programming, etc are the key areas of focus. Computer and IT engineering students can find important study material on this portal.
Thursday, 21 September 2017
C++ program to demonstrate use of local and global variable
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment