Geekpedia Programming Tutorials






Understanding C++ data types I

A small book for those beginners in C++ or even in programming who didn’t understand C++ data types. This is meant to be a patch to other books, that cover the basics of C++. Data types can be a little tricky sometimes, and difficult to understand, this book explains how data types work, and also shows you how to use them by giving examples.

On Monday, March 1st 2004 at 09:09 PM
By Andrew Pociu (View Profile)
****-   (Rated 3.2 with 10 votes)
Contextual Ads
More C++ Resources
Advertisement

Introduction



Book’s purpose

This is a short book for those beginners in C++ or even in programming who didn’t understand data types in C++. This book will only cover the C++ own types and will not teach you how you can create your own data types. There will be examples of how you should use data types and how you shouldn’t. This book is divided in separate parts, this is part 1. It will teach you C++ integers. Float will be covered in part 2 of this book.

What you should know

This book is for those who know the basics of C++. You can still learn data types from this book without knowing the basics of C++, but I recommend you to read a complete book first, and then, when you reach the data types lesson in that book, and after you read it, you read this short book too, to be sure you completely understand data types.

What you should have

I’m using Microsoft Windows XP as the operating system, and that means that this book applies only to Windows users, because data types differ in other operating systems like UNIX or Mac OS.
You must have a compiler of course, and in this book, we use Visual C++ 6 Enterprise Edition. It makes a difference which compiler you are using, because data types often differ from one compiler to the other.



What data types are


Data types

Many programming languages use different data types. This data types can hold different values. There are some data types that can hold small values, and use less memory, and there are data types that can hold bigger values, but use much more memory.


Adequate data type for adequate value
There is no reason for you to store a small value in a big data type, because the space that it occupies in the computer memory is wasted.
Let’s suppose you have a five characters word, like ‘aloha’, and the smallest data types you have can hold one character, five, or ten. Which should you use? Of course, if you can’t use the data type that holds one character because it has room to store only the first character, ‘a’. You can use the data type that holds ten characters, and the situation would look like this:





Not very clever. You’re wasting five additional characters. The five characters that will remain empty will be reserved, because you declared 10 characters to be used. Therefore, the remaining 5 empty spaces cannot be used by another instance of a data type. It’s reserved for this data type instance only. On the other side, you can expand the word later, if you wish, to a maximum of 10 characters. For example, you can write ‘alohaaaa!’ and fill all the empty spaces.
However, if you know this value doesn’t change why should you use the ten characters data type and not the five characters one?





You save memory space and at the same time, your program gains performance.

This was only an example to demonstrate you why data types are important. This is not a real-life example from C++. In the next lessons, we will work with more real-life examples.


Now you can read 'Understanding C++ data types II'
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by amna on Thursday, April 15th 2004 at 07:56 PM

i wwant to know abt some complete basic,and abt some programming.


regrads
Amna

by Andrei Pociu on Thursday, April 15th 2004 at 08:22 PM

Then try this:
http://www.geekpedia.com/prog_ttrls.php?id=11
http://www.geekpedia.com/prog_ttrls.php?id=12
http://www.geekpedia.com/prog_ttrls.php?id=13

by amir on Friday, May 28th 2004 at 10:08 PM

parallel port programing

by nassim on Friday, May 6th 2005 at 09:11 AM

hi
i want to know how to program th parallel port using

c++ version 5.02 ?
i tryed the c programs but the compiler gives me major
error. please explaine why.
thank you.

by rupesh tiwari on Thursday, July 7th 2005 at 09:17 AM

i want to write a program in c language for transfering data from one computer to another computer using parallel port in printer port.

by Octavia on Sunday, October 9th 2005 at 03:11 PM

I want to write a program in C++ that reads data from a file whose name is input by the user, and that outputs the first word following each of the first three comma in the file.

by me on Monday, March 13th 2006 at 02:38 PM

me too

by rajat on Tuesday, March 28th 2006 at 12:54 PM

i want to know about datastuructures in c/c++

by Innocent J on Saturday, April 8th 2006 at 08:07 PM

Seems like a great book, i hope I will like it!

by vijay sharma on Friday, April 14th 2006 at 10:56 AM

hello
i want to learn how to programing for port programing using 'c' language.

by Jone on Sunday, July 23rd 2006 at 04:15 AM

Hi anyone, i'd really love to learn programming but i dont have the essential tutorial notes and the appropriate software, anyone willing to help with good heart...?

by N26 on Saturday, January 19th 2008 at 05:38 PM

why are u muppets posting under data types? Parallel Port programming (is that for ur robot arm demo) should be under device slash hardware-interface programming... crickey!

PS. btw this first page of data-types is not well written, it\'s not that i don\'t appreciate the hard-work, but still.

by foo on Saturday, June 21st 2008 at 05:33 AM

Sorry just had to learn how to do this

by foo on Saturday, June 21st 2008 at 05:33 AM

Sorry just had to learn how to do this


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C++ Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons