C_10 Data Types in C - Part 1 | Programming in C

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the series of learning programming in c in this video we are going to talk about data types in c in the previous videos we have discussed constants variables identifiers and keywords in c language now we will discuss what are data types what is need of data type and how to use data type in a program what is use of these data types right everything about these data types we are going to discuss with proper examples right i'll try to relate this thing with some real life example also right and this video is brought to you by an academy because an academy in collaboration with code chef is going to start a course for programming it's like you can say a complete course to become an expert level programmer and the best faculties are going to teach you those are having tag of the finalist of icpc contest and in this program in this series of classes you will get those skills that are required to get into big tech companies or you can start your own tech companies or you can say that are required to crack any international coding contest so you can see the schedule here the date and who is going to teach you and the topic they are going to cover like the topic discussed would be basic data structures binary trees searching and sorting and everything they are going to discuss so they have added few courses but the more courses would be added soon as the batch progress so you can go for it and this is paid subscription so if you will use the code jenny 10 you will get some discount ten percent discount on the the spade subscription if you take that one year or six months paid subscription then after the successful completion of this course you will get an industry accepted codes code shift certification also that is free so if you are interested you can go for it all the details and the link for this course i'll give i'll put in the description box of this video you can go and check out now let us discuss data types in c see first of all take an example why we need this type data type see let us take in our almira we have different different space separate space like if you want to ah put clothes there is separate space for that there is one drawer also where you can put some other things there is also little drawer also within that drawer maybe where you can put your luxury items or cash so according to requirements you uh you take those that space you need that space it's not like that that small drawer you will put cloth right and also you can take one more example like suppose if you want to drink water you will put that water will take glass and if you want to eat something like if you want to uh eat any vegetable then you will take what that bowl there you will put that vegetable it's not like that you will put that vegetable in that glass so according to requirement you will take those things right in computer memory also according to our requirement we reserve space in that memory suppose this is computer memory and while i'm processing while i'm writing a program suppose i need some space so according to that i will reserve some space in this memory suppose i need more space according to that we reserve or the that computer will reserve that space for us according to our requirement right according to our type of requirement now how we specify how much space we need in memory that is specified by data types data types as the name suggests it tells you what the type of data you want to store some data in memory but which type of data you want to store whether it's a number like 12 whether it's a number like 1 2 3 4 5 6 a long number or whether it's a character like a or whether it's a string like jenny or maybe it's like one two point three four maybe it's a floating point number so which type of data you want to store here according to that that we are going to reserve that computer is going to reserve some memory for us so that we can use that memory we can access that memory right and when we name that memory like i have told you what are variables it's just a name given to a memory location so that we can easily access that memory like suppose i have given a here and suppose i have written a is equal to 12 and type is int so some memory would be allocated how many bytes that we will discuss the size of integer and there i am telling that you have to store 12 here the value is 12 and some address would be there like address is thousand let us suppose so this memory has been reserved for us so if you want to access this memory you can easily access the this by calling the name by printing the name only right how will print that also discuss so i hope you about why we need data types in c to tell or you can say to define the type of data that you are going to store in a variable so data type will tell what first the type of data which type of data you are going to store whether it's a numeric data floating point integer or character or a string second thing how much memory should be allocated to that data see we use data types to declare variables as well as functions so how many types are there how many types of data types are there first we have primary data types or you can say fundamental data types basic data types second we have drive data types and third we have user defined data types see primary are also known as fundamentals or built-in data types that are predefined in that library what comes under primary data types int float care and somewhere it is also written in that double but within uh you can also write here double also derived date types are see as the name suggests these are derived using primary data types so here we can say arrays structure pointer union these are what derived data types and user defined data types are type dev and enum enumerated data types see these are separate separate chapters in c so we will discuss these also in separate videos and enumerated also discuss in a separate video type def we can discuss here it's like you can give a name your name customized name to these data types like i am writing here suppose type def and data type the basic data type is int and i'm i want to give a name to this data type as suppose jenny so now when you write in a it means you are declaring a variable of type integer so rather than this we can also write here jenny a because here i have renamed this int as jenny so this is what user defined data type enum we will discuss in a separate video so now in this video i am going to discuss about primary data types what are these why we use and the stories they need right so first of all let us say int int is also further categorized in shortened and long end see this short and long these are what size modifier or you can say qualifiers and for that we also have two qualifiers sign qualifier or sign modifier that is unsigned and signed so these two types of qualifiers are there size qualifier short and long or you can say modifier and sign modifier signed and unsigned int stands for integer you can store here integer value let us say 12 1 1 to 3 these are integers value you can store here but now range of this integer is what suppose i want to store a number this one these many lines are there can we store using int so what is the range of integers it depends on that machine you are using you are using a 16-bit machine or 32-bit machine or 64-bit machine that depends completely on your machine right so on a 16 bit machine the range of this integer is what minus 3 2 7 6 8 2 3 2 7 6 7 this is the range and see here we are having both minus and plus so this is what for signed integer range is what signed integer if you say simply end by default it means you are using signed integer right signed means you can put the values negative also positive also but if you specify unsigned int then you can put values what only positive values no sign can be there no sign is allowed there in unsigned in and the range of unsigned integer is what because in unsigned we are not having negative values so it should should be started from zero so zero to six five five three five this is for unsigned integer this is the range that the the number you can uh take you can take between these ranges only right for a 16 bit uh machine i am discussing this and on a suppose only 32 bit machine if i write the range of integer that is this is a range this is the range for 32-bit machine so you don't have to remember this you just have to remember this generally they can ask this range right and now the memory taken by an integer is what it's two bytes but i'm not saying that it is a rule that integer will take two bytes only it depends on the machine you are using sometimes it use four bytes also and it it depends on language also you are using c language or java language so it's better to write a program whichever system you are using or maybe whichever language you are using according to that you can just write down that um one statement if you want to suppose find out that size of int so what you can write down just write down a simple program there you can write down percentage f uh suppose printf percentage value for it is for uh long integer right and here you can write simply size of size of it is predefined function that is in that library we include in that header files size of size of integer you want to check just write down a program and print this one like void main and everything obviously you have to write down it's not like that you just have you just need to write down one statement only and then the size would be printed whether it's taking two bytes or four bytes it depends on the system you are using the computer you are using the architecture you are using right but generally when someone ask or in colleges also they teach what the integer size of integer is two bytes but it depends right you need to uh remember this thing also now why i am writing this short and long short intent longing see sometimes suppose if you want to store single value like one i want to store so i don't need much space to store one and if i want to store like this number then obviously i need more space than one right more bits than one so according to our requirement we specify whether we are using less space then we can use this data type short int and if you want to store a phone number like that is a means a big number so you can use long it at the along at that time so according to your requirement you should use these specifiers rather than wasting space if you want to suppose inserts store only a number one so for that if you take if you use this size long end then the size of long end would be 4 bytes means long int number will take 4 bytes to store in memory and short int if you specify then that number would take only one byte to store in memory so if number is short so use this now why you are wasting space by using this only it is obviously going to slow your application only so according to your requirement use this thing that is why the modifiers are there short and long see here what does this mean suppose your ram is having a ram is of 2 gb only i know nowadays you are having laptops with 32 32gb ram 64gb ram ram but just it's a simple example i'm taking ram of 2gb so how many bytes how many bits that ram can store it's 2 into 1024 mb and rather than mb you can write into 1 0 2 4 k b and k b 1 0 2 4 bytes and if you want to convert it into bits then one byte is equal to eight bits into eight these many bits your ram can store if ram is only 2 gb so you can see how many size how many bits we can store right now let us discuss this is about integer now let us discuss about character but before that just want to give you some example of valid integer and invalid integer c so see this is what i am discussing it in the context of 16 bit machine so this is what valid this is signed integer this is also valid there is no space it is just 53 this one is also valid this one is also valid but this is invalid because here i am writing comma that is not allowed right this one is also invalid because this is decimal this is invalid because it is out of range for a 16 bit machine for integer and how you can print this in you just have to use the format specifier how you can print integer value using percentage d right now about character so it is going to store a single character right and how we will define that character type of variable you will use this keyword care and just write down the name of that variable suppose i am writing here a that's it this a is having value that is of character type and the memory size it will take how many memory how many bits it will take in internal storage if you want to store a character type of variable only one byte or you can say eight bits one byte is equal to eight bit right character can be signed and unsigned but ah both will take how many space one byte only both signed and unsigned by default if i write carry it means it is signed character and the range of signed character would be plus 1 to 8 2 1 2 sorry minus 1 2 8 2 plus 1 to 7 and for unsigned it ranges from 0 to 255 because here it is unsigned so no negative value can be there see why this range is this one and why the range of integer was this one because using one byte using 8 bits we cannot store a number greater than 127 and less than minus 128 same with integers you cannot store a number greater than that range uh using that two byte of space because integer will take two byte it depends actually upon upon that system you are using right and the format specifier we use for printing care is what percentage c suppose in a program i am writing printf percentage c and if suppose i am printing here value 98 then what should be the output percentage c means character should be output right it means after that this comma the first number it will print what character value but here we have 98 so you will say that 98 would be printed no sky value this is sky value for which character small b so character b would be printed the output would be b here so now next is float it is used to store decimal points decimal values fractional values and the memory size it will take is 4 bytes the range of this float is this one minus 3.4 e 38 is e means i'm writing this number because it is a long number so i'm writing this number in form of exponent form this is mantissa this is exponential form right now float is how we declare this variable float float a we can also say it real numbers decimal numbers or floating point number right float a means the value of a should be floating point number and suppose value of a i am initializing like 10.1 right or you can initialize ten point zero also it is not equal to ten ten is integer ten point one ten ten point zero is float so if you will print this a the format specifier you will use for float as percentage f and a then what should be the output ten point the float will take six digit of precision is in this size in four bytes four bytes means four into eight bits in these bits we can store up to six digit precision number right and float is also having classes or you can say uh it is of type double and long double these are you can say three classes of a float type of variable float double long double now it is taking four bytes double will take eight bytes to store a number if a number is long double sorry double then it will take 8 bytes to store in memory it if it is long double it will take 10 bytes to store in memory right and the range would be greater than float and the long double range would be greater than this double but you don't need to remember these ranges because they are very lengthy right and to declare a variable of type double you will write double suppose i am writing here salary if i want to declare long double you can write down long double salary this name in memory space would be allocated how many bytes 10 bytes right and for this average how many space would be located in memory 10 sorry here 8 bytes and here the space would be located for 10 bytes and yeah for double to 1 if you want to print a variable or a number that is of type double then here you will use lf lf and here you can write this salary right and if you want to print a long double number then what you will use percentage capital l and f see i'm not sure but you can search it and you can tell me if i am wrong in the comment box the format specifier for this long double right and one more difference is what the number of precision after decimal is what six digit in float and in double its 14 digits so that number is having more accuracy right if you want to perform some calculation which required more accuracy then we will take this data type right otherwise i will take float right and next is our void data type but void we don't use to uh we don't use with variables void means empty nothing is there so we use generally this data type with functions if a function do not return any value then we declare that function as void type type is word a type is word but we generally don't declare this void with variable name right so you can say it is a special data type which cannot store any constant value it word means empty right now let me draw a table of these all these data types so this is the table just for your reference it's not like that you need to remember everything this is data type this is range of the data types then size in bytes and then this is format specifier this is for you you have to tell me what is the format specified to print shortened and unsigned shorten so you don't have to remember everything here because i have already told you the size depends and the range depends the machine you are using 16-bit machine 32-bit machine 64-bit machine this is i'm writing on the basis of 16-bit machine in the context of 16 bit right so now i guess that's it for data types in c now that's it for primary data types in c uh one by one we'll discuss now derived data types as well as user defined data type that is enum data type right so now i'll see you in the next video till then bye bye take care
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 91,551
Rating: 4.9048057 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures, what is data type in C, types of data types in C, primitive data types, derived data types, user defined data types, data types in C, introduction to C, introduction to programming, programming in C, what is variable in C, keywords in C
Id: NyT9vvSBoeo
Channel Id: undefined
Length: 21min 16sec (1276 seconds)
Published: Sun Dec 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.