BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Right Header

HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 3rd Semester > Object Oriented Programming

Object Oriented Programming By Mam Sidra Malik


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 14-10-2008, 01:51 AM
BSIT07-01's Avatar
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Scope of Variables C++

Scope of variables

The scope of variables declared within a function or any other inner block is only their own function or their own block and cannot be used outside of them. For example, in the previous example it would have been impossible to use the variables a, b or r directly in function main since they were variables local to function addition. Also, it would have been impossible to use the variable z directly within function addition, since this was a variable local to the function main.
Name:  Scope of Variables C++ [BZUPAGES.COM].gif
Views: 211
Size:  4.6 KB


Therefore, the scope of local variables is limited to the same block level in which they are declared. Nevertheless, we also have the possibility to declare global variables; These are visible from any point of the code, inside and outside all functions. In order to declare global variables you simply have to declare the variable outside any function or block; that means, directly in the body of the program.
Reply With Quote
  #2  
Old 14-10-2008, 02:05 AM
BSIT07-01's Avatar
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Re: Scope of Variables C++

Static Variable

Syntax:
Code:
static int n;
we use static keyword before declaration.

One use of Static Variables is in functions,
when we want to store a value within a function, and not want to destroy it even when the function is ended...
eg: we want to know how many times a function is called.
Code:
void myfunction()
{
static int count=0;
/* Body of Our Function

*/

count++;

}
Static variable count is created when first time we call this function. And is not destroyed until execution of whole program is completed.

when ever we call this function, count is incremented by 1.
So We may easily calculate the number of times a function is executed
Reply With Quote
Reply

Tags
c++, lectures, scope, variables


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scope of Auditing usmanstar Auditing 0 02-06-2011 10:16 AM
Lecture 22 Multiple Random Variables bonfire Statistics and Probability 0 15-04-2011 01:33 AM
Variables, probability distributions, marginal and joint distributions and density functions bonfire Statistics and Probability 0 15-04-2011 12:11 AM
Concept of random variables, discrete and continuous one and two dimensional random bonfire Statistics and Probability 0 15-04-2011 12:06 AM
Chapter1-Nature and Scope of Economics; Book Fundamental of Economics; Author Sheikh Ramzan .BZU. Economics 0 10-03-2010 06:41 PM

Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 04:44 AM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.