3.3 LOCAL VERSUS GLOBAL VARIABLES

So far we have seen that the information is passed to a function through parameters. It is possible to pass information to functions other than parameters through global variables. The variables declared outside (and above) the function becomes a global variables for such function.

Word global means universal, available everywhere. In programming, it means such variables are available for use in function main() or any other user-defined functions. A variable declared inside any function is called a local variable. Its scope is for that function itself. It does not have existence outside that function. Program 3.3 will help to understand these concepts.

Problem: Write a program to read the marks obtained and calculate ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.