Storage Classes in C | C Language Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone welcome to nourish technologies which is cinemas in this session we are going to discuss about a storage glasses concept storage glasses in C language so what is storage squares means generally in the Declaration of every variable right suppose I am declaring one variable so variable name so technically we can call it as the identifier suppose variable name is a in the Declaration of every variable we need to specify its data type we know why we need to specify its data type suppose if it is integer data type this data type is representing what is the size of variable and how much memory is allocated and what type of data is allowed to store these many things it will represent but along with that we need to specify its storage class also storage class suppose for example Aldo is one storage class in the Declaration of variable we need to specify not only its data type also it's a storage class so what storage class representing so what data type is representing data type is representing what is the size and what is the type of data is allowed type of data and what a storage class is representing so many things a storage class is representing what is the default value right what is the scope of variable what is the lifetime of variable where we can access where it gets memory allocation so many things it will represent okay now the discussion about the storage classes sir suppose if you are not writing any storage class in the Declaration of variable what will happen simple according to the context or according to the area so where we are declaring a variable depends on that compiler will write one default storage class so that I will show you okay so this is simply the syntax of a storage class this is a syntax and this is one example so one type of storage classes is auto read how many types we have and all will see totally how many types of storage classes we have right types first one is a automatic storage classes second one is a resistor storage classes third one is a static storage classes fourth one is a external storage classes total four types of storage classes we have okay and along with this if you want to declare a variable inside the program right in how many contexts we can declare a variable this is nothing but the scope of variable first scope is a block scope within the block or within the method method is also comes under one type of block only okay and one method can have n number of blocks also like if block else block for loop while loop all these are also comes under blocks okay so block scope second one is a method scope third one is the program scope program scope a variable right so can be under block scope or method scope or programs code first we will see so what is black block scope what is Method scope and what is the program scope okay see for example one function or one program we are writing remain executions as from a inside the main method so directly we can write a blocks just open brace and close brace is nothing but a block inside the block I am declaring a variable with the value 10 and here it is whenever we are printing the value printf a value I want to print a value here it is inside this block a value is a 10 so whenever we are printing here it will not give any error message right it brings value 10 but once the control come out of the block here I want to print the value printf a value we are printing a value here it will give error message cannot find symbol errors a variable is undefined symbols why what is the reason means once the control enters into a block this variable is having block scope only we can access only within the block once the control come out of that block we cannot access this is what we called block scope this variable is having block scope variable is having block scope variable from outside of the block you cannot access that variable and next what is the method scope or what is the function scope method and function both are same okay see what is the function scope suppose here we are writing two functions in one program one is the main function second one is a wide just check this is another function one C program can have n number of functions we know this concept collection of functions will give a program now inside the main method I am declaring one variable in a it is a local variable it is a local variable see what are the properties it is local variable is the first one and next one it is having a function scope because it is defined inside the function inside the function and so what is the initial value is a garbage value it holds garbage value it holds garbage value next and here we are writing one block in a equals to 10 and we are printing printf percentage D a value we are printing a value and next outside to that block also we are printing a one percentage D a value via printing and next here also we are printing a value printf percentage D a via printing here it is first here a value is initialized with a garbage value and next once the control enters into this block into this block now here a value is a ten this is another a variable declaration here a value it will print 10 but once the control come out of the block and here we are printing a value it will not print this value because it is belongs to this particular block own it is looking for some method scope or a function scope variable here what is it a value a value is a garbage value so here it will print garbage one suppose if you are accessing check function here we are accessing check function control come to check here whenever we are trying to print a value it will give error message it will give error message why what is the reason means here what you declared the variable that is available only within the main function from outside function you cannot access any variable if you are trying to access it will give error message simple okay now what is that program scope right see what is the program scope means suppose globally I am declaring one variable into a is equals to 10 next here it is the two functions we are writing one is a wide main function inside I am declaring variable a is a value 20 consider and we are writing one block inside the block we are declaring a and here we are printing a value printf % SD a next inside another block we are writing a is equal to a plus 10 and here it is we are printing percentage D a value this is and next so we are writing one more function like wide check function check and here we are printing that a value percentage D a value we are printing now observe first execution starts from main here global variable is there this is what we called program scope this is program scope variable and this is function scope variable and this is block scope variable first the control enters into block beside a we are declaring but no initialization block variable is nothing but a local variable what is the default value of local variable is a garbage value so here it prints a garbage value next once the control come out of that block now the control enters into another block inside we are updating a value a is equal to a plus 10 where it will update cert here or here here this variable is belongs to this particular block only and this block this block is will affect here because there is no local variable so a is equals to a plus 10 means here it will affect a placed in value 20 plus 10 value 30 next the control come out of the block it is also belongs to method scope only here whenever you are printing a value it will print 30 and next suppose if you call check function here if you call check function here then the control come to check function inside the check function we are printing a is there any local variable here no so it is connected to program scope variables so here a value it will print 110 so this program is representing different types of scopes representing different types of scopes okay this is all about the introduction part of a storage classes and so what are the different types of different scopes of variables okay in the next session we'll see right so what are the different types of storage classes available in a C language okay so thank you for watching thank you [Music]
Info
Channel: Naresh i Technologies
Views: 229,989
Rating: undefined out of 5
Keywords: Naresh IT, Learn C Language, Hands on C Language Training, C Language Demo, Online C Language Training, C Language Tutorial Videos, C Language Overview, C Language Interview Questions, Storage Classes
Id: Ahgl3x_EP7o
Channel Id: undefined
Length: 12min 36sec (756 seconds)
Published: Thu Feb 09 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.