adspace


explain about scope and storage class in oops

Answer Posted / Jasvant Singh

In Object-Oriented Programming (OOP), Scope and Storage Class are essential concepts that determine the visibility, accessibility, and lifespan of variables and objects within a program. Here's an explanation of both:

1. Scope:
- Local Variable: Declared within a function or block, visible only within that scope.
- Global Variable: Declared outside any functions or blocks, accessible from anywhere in the program.
- Static Variable: Declared with the `static` keyword, maintained between function calls but still within the same scope.

2. Storage Class:
- Automatic (or auto): Created when a function or block is entered and destroyed once the function or block exits. Example: local variables in C++.
- Static: Allocated and deallocated only once during the entire execution of the program, maintaining its value between function calls. Example: static variables in C++.
- Extern: Declared outside any functions or blocks with no initial value. Used to define global variables that are shared across multiple source files.
- Register: Optimization directive to store a variable in a processor register instead of memory, which can lead to faster access times but limited space. Not supported by all compilers.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

hi, i applied for AIRPORTS AUTHORITY OF INDIA for the post of AIR TRAFFIC CONTROLLER(ATC)..so plz send me the sample questions to my id...88arun@gmail.com

2362


can any one send me the configuration of cisco 1841 router????/

1970


Can anyone send me iocl written test paper fro computer engineers

2374


What is the instruction to load the register B?

2442


HELLO ALL OF U.I HAVE QUALIFIED IN SBI CLERICAL WRITTEN EXAMINATION AND MY INTERVIEW IS ON 20TH OF THIS MONTH.IAM SOTWARE BACKGROUNDED CANIDIATE SO CAN ANY ANYBODY WHOSE INTERVIEW IS OVER CAN TELL ME THAT WHAT QUESTIONS THEY ASKED RELATING TO COMPUTER SCIENCE.

1950


need tcs questn papers from 2007 to 2009 plzzzmail to 9015.rama@gmail.com its urgent

2031


What would be your first invention?

1257


please send me latest Aptitude Test paper

2275


Write a function that responds to a click anywhere on the page by displaying an alert dialog. Display the event name if the user held Shift during the mouse click. Display the element name that triggered the event if the user held Ctrl during the mouse click.

2131


i need NIC written test paper or give me any idea about written exam.Plz send me at smileever8@gmail.com

2352


what is the different between view and materialized view in oracle DBA?

1752


Please send me the ongc old question papers

3168


pls send me the e-book for verbal and non verbal reasoning of R S aggarwall

2313


sir, please send me the last three years exam papers conducted by CPCL- RECRUITMENT EXAM FOR Recruitment of Engineer ELECTRICAL ENGINEERING. A Soon as possible. i would be greatfull to u

1960


why c is called middle level langauge?

2111