typedef in C - Part 2 | C Language Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to nourish technologies this is cinemas in the last session we have discussed the introduction part of a type def variable right so using type def declaration so we can create synonyms to the available data types in the application okay and how to create a synonym to primitive data type and how to create synonym to derived data type we have seen in the last session now in this session right how to create write identities to complex data types like user defined data types and point of data types we'll see okay see first one first one type def declaration for user defined data type type def declaration for user defined data type very simple so generally here it is a user type is a structure we are taking structure so generally how to create a structure how to create a structure struct struct suppose any structure students structure employee structure so whatever you can take suppose EMP is employee the employee is having three things so one is the employee number employee name employee name is a character array type employee named employee cell employee cell this is structure declaration and here it is what is the data type this is data type combinely struct EMP so combinely we can call it as a user-defined data type combinely you can call user-defined it so suppose i want to declare a variable how can we declare a variable struct struct EMP this is a data type data type this is variable e then he gets memory allocation but here it is a bit confusion so generally if you go for a primitive data types or if you go for derived data types right so data type name is only one but here it is in case of user-defined data types it is a bit confusion sir because here it is a two words combined Li is giving data type right how to avoid this confusion with the help of type def declaration if you write like this but more clearly for example we are writing employee as of now if you consider this struct EMP is a data type and employee is a variable but before this struct EMP just consider if you place type def declaration if you place type def declaration so then what will happen from now employee is working like a duplicate identity of struct EMP now these two are same here it is a two words so original name is a two words but duplicate name alias name is only one word now you can identify very easily suppose I want to declare a variable so generally how to declare a variable struct EMP yi we are declaring e is a variable and struck TMP is a data type but in place of a struct EMP simply you can write employee employee e e is a variable of employee type now it is very clear when compared with this one right easily we can understand this one right so this is one advantage of an alias name okay just to make a data type is very clear so mostly user-defined data types instead of writing struct EMP it is better to use a single word employee and one more thing the complex data types or undefined data types in C language right so we can specify with a very simple words how so that we will see so with the example look at this how to set write user-defined identities nothing but alias names too complex data types so what is the complex data type observe generally in a c language in a c programming strings we are representing with the help of character pointer okay for example this is my program in the main method here it is I am declaring one character pointer a type variable character pointer so variable name is a name variable name is a name next we are calling one method read method so read function we are calling this is read function it is not taking any argument inside I am declaring one character pointer variable it is also variable name we can give same name because two different places and next here it is we are asking printf enter name enter name then they will input that we are collecting with the help of gets get is here it is we are passing that name after reading we are returning that name written the name so name actually contains it is a character in a character pointer it holds address that address we are returning see name is of type word character pointer type so return type of this method return type of this function is also character pointer only this is character pointer read method is a character pointer type okay so whatever it is returning so that we are collecting here into name name and here we are printing that name printf name or welcome percentage yes a message we are giving in case of that we are printing the name execution starts from the main function this is declaration of variable name next for assignment operator right side data execute control come to read function here we are declaring one local variable we are reading one name and we are returning that name to the calling function that we are collecting here and printing so what is the prototype of read method prototype also we are specifying character pointer read and here it is not taking anything so you can specify wide also here and here also sir I want to specify no problem you can specify just to follow the standard rules here problem is sir character pointer can points to a single character and character pointer can point in to multiple characters also more than one character also it can point into writer in that situation here you are specifying character pointer means it is pointing to single character or array of pointers nothing but a string is a bit confusion reason in C language string datatype is not present so that is why with the help of type def declaration we are creating string datatype how simple suppose character pointer name we are changing to string name we are changing two strings or how can we change that before what we are placing type def declaration we are placing finish so whenever we are writing type def from now string is working like alias name two character pointer so then the complete program rights will be replaced with a string whenever you are writing character pointer so that will be change to string and here also character pointer change to string and here also return type is a string here also return type and the declaration type is a string now this program is very easy to understand what type of variable you are declaring it is a string type variable so that easily the programmer can understand okay this is array of characters it is not a single character okay so to the complex data types we can set easy identities so that readability will increase of your program this is one thing and next another thing another thing in dynamic memory allocation we can decrease the size of instruction with the help of type def declaration how it is possible for example a very huge instruction right so we can convert into very small instruction with the help of type def declaration see for example here it is we are taking so one node struct node struct node inside that so this is a single linkedlist node consider single linkedlist node right how to create this truck node single linkedlist node means so one is a data field and one is a Link field Link field is of type what struct node type struct node star this is a Link field just go through dynamic memory allocation concept or data structures concept to understand this one single linkedlist concept already we discussed write data structures using C language or data structures through C language so already we discussed single linkedlist also we discussed so now so we are applying type def declaration to so this single linkedlist node okay suppose if you want to allocate the memory dynamically to this node how we will allocate the memory using a manag function Emma look to the MLR function we need to pass the size of this node so we are passing size size of struct node size of struct node it will return the size of the struct node so that we are collecting into any pointer variable suppose I am declaring one pointer variable to this one struct node are any variable suppose PTR after creating or after allocating the memory for this node structure with the help of ml of function we are collecting into PDR but PTR variable is of type word struct node star type here it is so we need to typecast in to struct node star type this is type conversion actually this much you have to write this much so instead of writing this much I will convert how we can convert means with the help of type def declaration so what is the type def declaration very simple very simple observe type def type def struct node struct node so 1 is a general variable variable name I am writing node variable name I am writing node actually now it is not the variable this is just a user-defined data type of struct node type and next one more pointer type declaration type def struct node struct node star PTR two variables we are creating two variables we are creating now observe in place of a struct node you can write a node in place of a struct node star we are writing PTR we are writing PTR then now I am declaring the variable I am declaring the variable how I am declaring the variable observed nothing but this one we are rewriting as first I am declaring the variable struct struct node star write is something like anything variable name I am taking root considered root and here it is root equals 2 so first I am writing as usual so later I will substitute node struct node star ml log function it is taking size of the node size of struct node this is we are passing now observe here it is in place of a struct node star what we can write simply PTR we can write in place of struct node star we can write a PT R this is simple because PT R is already representing struct node star and next one in place of struct node star again instead of writing this much we can write only PTR it is easy and next here also in place of sizeof struct node nothing but in place of a struct node we can write simply node this is easy so nothing but what it is representing ml log function is taking sizeof node after that we have to convert we need to typecast this is pointer type testing in place of a struct node we can substitute node value in place of struct node star we can substitute PTR value so this is the advantage okay so in many ways we can use the type def declaration write to write the programming c programming very easily so these are the main concepts of a type def declaration right so thank you for watching this video for more videos please subscribe to nourish 80 channel thank you thank you all
Info
Channel: Naresh i Technologies
Views: 100,011
Rating: 4.8652425 out of 5
Keywords: C Language, Recursion in C, Srinivas, Naresh IT, Hands on C Language Training, C Language Demo, Online C Language Training, C Language Tutorial Videos, C Language Overview, C Language Interview Questions
Id: 3_9_Vfdsq0s
Channel Id: undefined
Length: 15min 56sec (956 seconds)
Published: Sat Oct 29 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.