Interview/Exam Question related to C Q.What is Class in C or What - TopicsExpress



          

Interview/Exam Question related to C Q.What is Class in C or What Storage Class means in C ? How many types of Storage Classes exist in C ? Ans. Various Storage Classes in C classifies the variables location(i.e in Memory or in CPU Register), its life time, its initial value, scope of variable(i.e where it can be accessed in the program). There are Four types of Storage Classed in C 1. Automatic : Variable of this type of class allocates space in Computers Memory(i.e RAM), its initial value is garbage value(thats why it is better to initialise Automatic variables with 0 or 1 if addition or multiplication, is not be performed on them respectively.Its visibility is limited to the block(function scope etc) in which it is defined. It exist till the block is execute(in which it is defined). So far we have used this Class of variables in our program i.e Default Storage Class in auto. Whenever we use int a; or int x; statements then by default they belongs to atuo other wise you can specifically use auto int a or auto int x statements. 2. Register : This class of variables stored in CPU registers instead of Memory(RAM), its initial or default value is Garbage Value, their life and scope is same as of auto class discussed(above). To declare variable of Register storage class we have use the statements like register int a; or register int x; etc. Variables of this Class can be accessed by Program faster then other Classes so they can be used when faster and frequent access to the varibles required. 3. Static : As the name suggests variable of this Class maintains there value between the function calls(i.e they did not get re-initialised again) as against to auto class. They stored in Memory(RAM), initial value /default value is 0, their life is till program execution or till the function/code block executed in which they are defined. Variables of this Class are declared by using static int a; or static int x; statements. 4. External: Variable of this Class provides the facility of their accessibilty to all the functions in the program. They declared outside the functions but accessible to all the functions in the program. i.e they are Global.They stored in the Memory, their default or initial value is 0 and their life is till the program execution comes to the end or till the program is running.They are declared with the help of keyword extern eg: extern int a; or extern int x; If one need to access or use the extern variable in the function block then it is extern keyword is required to avoid conflict with local variable of same name.
Posted on: Fri, 02 Jan 2015 04:54:35 +0000

Trending Topics



Recently Viewed Topics




© 2015