Udemy

Primitive Data Types in C++

A free video tutorial from EDUmobile Academy
Programming Made Easy
Rating: 4.2 out of 5Instructor rating
46 courses
168,438 students
Primitive Data Types in C++

Learn more from the full course

Learn C and C++ Bootcamp for Beginners

Master the C and C++ programming language with easy to understand examples

05:03:30 of on-demand video • Updated February 2017

Write a Program using C Language
Write a Program using C++ Language
English [Auto]
Hi welcome back. Let's jump right in. This is a C++ program Anderson and you can see that many things about this program will look unfamiliar to you but many things will look familiar to you if you're familiar with C.. We have an Include statement here. We're not including IO stream dot H. We don't have to use the age or age extension we just know the compiler just knows that this is a C plus plus header file but it is an angle brackets meaning that it is in the CPG library. We have a main function here. We're not using a carrot or a character pointer and then a pointer to an array of characters or an integer pointer and a pointer to an array of characters. We are just using essentially what in C we would say as this in plus plus if we don't have any parameters to a function we do need to include void there but it's returning an integer and we're returning a zero from the function. We have two forms of comment. Essentially we have a single line comment which is two slashes. We also have multiple multiple line comment which is a slash and a star. And then if we terminate that that covers that goes to multiple lines and so forth. So again I'm using the genie Ideally the genie ID is extremely simple. Basically we can set we can create a new file give it a C-p extension number off and running. I'll leave it to you to look at things like the preferences to increase the font size the backgrounds. Some things like that but we will go through the bird process in geany and in C++ and of course see we must both compile and link our program. Compiling is by default. Eight building compiles and links the program so that's half nine. And then we can execute the program right from the genie editor right here using ephod. OK. So let's talk a little bit about data types. I'm going to kind of waved my hands here at this as TB. Colon colon see out for now just know that what we're doing here is we're using C output and we're outputting a string to this. So if you're just kind of copy and paste and you can output Hello world if you want to. We're going to talk very shortly about what to see out and some other things mean. So for right now though we want to get a handle around the various primitive data types in C++. So as you can see we have a size of operator so we can get the size in bytes of each data type as in C we have such modifiers as short and long signed and unsigned. I haven't used those here because the point is with this piece of code is we went to see the bite size of each of these types. So what we're doing here is we are logging out the size of a car. This should be familiar to you. This kind of thing should be familiar to you from the size of a car. We would do it exactly the same way. There is a wide character type w car underscore key the underscore t means type. So it's a wide character type. There is a short int and int and a long int in C plus plus like in C. These are going to be system dependent. They may be different byte sizes on your system than they are on mine but there is a short and a long there is a Boolean type unlike in standard C. This is our true false value and boolean type. I will say even though it would only need to be one bit wide. It is one byte wide. It's the same size as a car. We have a float and a double. And of course we have a long double. Now I'm running this on a 64 bit operating system. If you're running this on a 32 bit operating system these your mileage may vary. But let's go ahead and compile and build the program and then we'll run it and we'll see our output. So we see a car is one bytes this wide character type is a four byte type of short and is two bites and is 4 bytes long and is 8 bytes. The boolean type is one byte as I already said. And then a float is for a double is eight and a long double is very precise indeed 16 bytes. So now the difference is between or the difference in these bite sizes of course is how many digits of precision with floats and doubles and long doubles. The interesting aspect of the bite size is how precise the value can be with ENC with shorts and longs. The interesting fact is how big or how small. In negative terms the value can be. So we have eant short in long. We have float double long double increases of bytes are precision for floats and doubles and long doubles and value for its shorts and longs. Thank you very much.