C++ Beginner : How to Using Local, Global Variables In C++

C++ for beginners : how to Using Local Variables and Global Variables In C++, if local variables will be using in functions and global are defined outside of all the functions

C++ for beginners : How to Using Local Variables inside a functions or block and Global Variables outside of all the functions In C++? As we know, the c++ programming language also have variables was defined in a of functions or a block or outside of the functions.

Read : C vs C++ programming Languages
If Statements in C++

Today we will learn C++ programming languages just for beginner, where we learn how to using local variables and global variables in a functions or block.

How to Using Local, Global Variables In C++

Local Variables

Local variables can be declared inside a function or block. A local variables only can used inside of a functions or a block, the statements that are outside the function cannot use this local variables. Here is the example using local variables :
#include 
using namespace std;

int main (){
  // Declaration Local variable
  int x, y;
  int z;

  // initialization block
  x = 5;
  y = 15;
  z = x + y;

  cout << z;

  return 0;
}

Global Variables

Global variables is declared outside of a block or a functions, the global variables are usually declared in the top line of a program. Not just for programming language C++, but almost the entire programming language has same with the C++ language.

The virtue of global variables is accessible to of anything functions in the programs. because a global variable is created to be accessible from the existing all in a program. Here is the example using Global variables :
#include 
using namespace std;
 
// Declaration Global variable
int x;
 
int main ()
{
  // Declaration Local variable
  int y, z;
 
  // initialization block
  y = 25;
  z = 55;
  x = y + z;
 
  cout << x;
 
  return 0;
}

A Program may have the same variable name for local and global variables, but the value used is the value of a local variable. As an example:
#include 
using namespace std;
 
// Declaration Global variable
int x = 100;
 
int main ()
{
  // Declaration Local variable
  int x = 25;
 
  cout << x;
 
  return 0;
}

When the program is running will result "25"

COMMENTS


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,89,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,6,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: C++ Beginner : How to Using Local, Global Variables In C++
C++ Beginner : How to Using Local, Global Variables In C++
C++ for beginners : how to Using Local Variables and Global Variables In C++, if local variables will be using in functions and global are defined outside of all the functions
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXnTDFXHwP99XcXpb1We2M522LRZrNeTD8UcYNb0KicUtQqQneliRc5asAS6F2kAQPU4fsa2315TjGOOYjShDFzcM865Gl0M4V0Sl634gQITTjIaZg5a6bhr_LXfapRDjtTVtir4wutZU/s320/variables-c-plus-plus.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXnTDFXHwP99XcXpb1We2M522LRZrNeTD8UcYNb0KicUtQqQneliRc5asAS6F2kAQPU4fsa2315TjGOOYjShDFzcM865Gl0M4V0Sl634gQITTjIaZg5a6bhr_LXfapRDjtTVtir4wutZU/s72-c/variables-c-plus-plus.jpg
KODE AJAIB
https://scqq.blogspot.com/2016/06/c-beginner-how-to-using-local-global-variables.html
https://scqq.blogspot.com/
https://scqq.blogspot.com/
https://scqq.blogspot.com/2016/06/c-beginner-how-to-using-local-global-variables.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy