Here are some basic Q&N about C Data types.

Which data type is most suitable to store the size of a hard disk partition?

So 10-gigabyte partition size, number one, integer, unsigned integer, long, unsigned long. So please go ahead and then write on a piece of paper the answer for test one. So Here’s the answer. The answer is B, let’s go to the second one.

Which data type is most suitable to store the data of an eight-bit microprocessor or microcontroller?

char or characters. Unsigned characters, integer, unsigned integer. Again, pause for two seconds, note down your answer on a piece of paper. Okay, so the answer is the unsigned character. Let’s move on to the third one.

Which data type is more suitable to store the length of a string C strlen() function is just an example. Integer unsigned integer, long, unsigned long. So the answer is unsigned long. So these are the three test questions that I have created for us to think deeply about the choice of data types for our programming variables. If you got all three of them, right, then I am sure that you understand what you are really doing. I have seen many people. They don’t have considerations for it. So I am going to explain in quite a detail. So I’m also going to explain the reasons behind why the answers are for all three questions with some good real-life examples also. Okay. So please continue to watch this video. This is just an introduction to our data type in the C programming language.

We are now going to introduce it once I introduce the data types and primitive data types. Right. Then I’m going to come back to these three test questions and I’m going to explain in detail the answers – why the answer is what is written there, actually. Okay. Plus some examples plus some real-life examples I will also depict for these three examples. So what’s the data type definition? The data type is information generally about the type of data you store in a particular memory address. See in C programming and in general, any programming language, we need to store some programming variables.

A Variable can be a one Byte variable. It can be a two Byte variable, four Byte, random number of bytes, collection of a lot of variables by some named object. Right. So we have to remember that in programming we have to store the data when we store the data in memory. Now we need to assign a programming construct for that. Is that memory represents just a sequence of characters, or is that memory represent a byte? Or does it represent an integer? Right. Or does a memory represent a floating-point data type? Right. So we store the data in memory, and then we must assign a type. Right. So think about integer. We generally use integer X. So integer mostly on a 32-bit system. Sorry. Definitely, in 32-bit systems and 64-bits systems, the integer is four bytes. What about the float Data type? A float is also four bytes. So now there’s a piece of memory where you are storing either an integer or afloat. So there are four bytes allocated. Right. So it’s a piece of memory.

Now, you must attribute a programming construct in terms of data type for that. And that is what is data type is about the type of data that is stored in a particular memory location. Now, since this is an advanced course, my understanding is you will be knowing some of the basic C-related constructs, data types, and everything about C on a simple, fundamental level. Right. So we’ll quickly skim over and try to understand different types of data types, which are given by the C programming language. So you have a primitive data type, you have a user-defined data type, and then you have a derived or dependent data type. So this is one kind of classification you can assume for the C programming language. Let’s go deep into each of these primitive data types. Right. So if you study Kernighan & Ritchie, the best book. Right. So the best one in C. And he has introduced the concept of primitive data types, and it’s a very nicely designed construct. When you think about programming in general, we need to allocate a piece of memory to store some data. Okay. So when you see the character.

So when you’re talking about character data type, what is coming to our mind? We really need a piece of memory to store one byte of information. Okay. So the way it has been designed is we require a data type to store one Byte of information or short all of, you know, is the two bytes of information integer, four bytes, long again, four Byte or maybe an eight Byte. And then you have floating-point real numbers and then double four bytes and eight bytes and then void. So let’s cover each one of these in some more detail. Right. So when you talk about character data type, the focus here is we require a construct. We require some support from the programming language to declare and find one storage space for one byte and store the data. Many of, you know, a character generally mean the symbols.

Right. So we have an ASCII table. So all the symbols are represented in an ASCII table, and you have an ASCII value for it. Right. Unsigned 8. Sorry, you have u_8 We call it. So, you will have one byte of representation, character is just one Byte representation. It does not mean that it’s the character always like ABC, whatever symbols you see on your keyboard. Okay. The character can have value because ultimately in the memory, what do we store? We store bits. So think about the Byte. You have eight bits of information. That eight bits of information can be always written in terms of some character. For example, the capital letter A, the keystroke. Capital letter A, So we define a programming construct or a variable char C or character C equal to an in quotes. Single quotes. Are we ‘A’ storing in the memory?

The answer is absolutely NO, we are not storing that A in the memory. So what do we store? It gets converted into the equivalent ASCII value or the so-called decimal value 65. Capital A 65. So in memory, we are storing 65. And what is 65 in binary? 65 in binaries … 0100 0001 Right. Okay. So you can definitely write it in terms of binary, and that’s what gets stored ultimately in memory, whether you have any of these programming constructs, any of these variables in memory, we are always going to store in terms of bytes and internally in terms of bits. Okay. So I repeat, the character is definitely a character. And. But the way it is stored is in terms of bits and bytes.

It’s basically a number. Now, we had a requirement in the Grand old days when we had the C programming language. The programming language was done almost around 1970. Right. So we are close to 50 or 50 years that programming language has been created. Right. At the time, we rarely had 32-bit to 64-bit operating environments. We did have. But Yeah. So at that time, when there is a requirement to store an integer value. Right. So we wanted to program construct for an integer value. And then when you say integer value, we’ll have a lot of 16-bit processors or 16-bit microprocessors or processors. And then they said, you want to store that data. So they created a type known as short. It is short, or people call it a short integer. I repeat, it is a short or short integer.

Leave a Comment