C++ Tutorial - Data types

CoderSource.net
C++ Tutorial - Data types
Rating:

Date: 5/1/2004 12:00:00 AM

   C++ practically offers most of the necessary data types except for a basic data type string. This is a big trouble in C++ without such a good feature. 

   Anyway, this c++ tutorial will discuss the basic data types necessary for c++ programming.

C++ tutorial - Number data types:

int:

   This int keyword is used to declare integers, whole numbers either positive or negative. Most of the compilers treat this with a size of 2 bytes. i.e.,integer of 16 bits length. The following statement shows how the variables of int type are declared. 

     int var1; 
     int var11 = 10; //Initialization for c++ tutorial

long:

   This long keyword is used for declaring longer numbers. i.e, numbers of length 32 bits.

float:

   This keyword float is used to declare floating point decimal numbers. A sample declaration would be, 

         float var2; //Sample declaration for float

C++ tutorial - char data types:

char:

   This keyword is used to declare characters. The size of each character is 8 bits. i.e., 1 byte. The characters that can be used with this data type are ASCII characters.

string:

   This is not a basic data type with C++. Instead array of the char data type should be used for a string variable. 

     char strvar1[200]; 
     char strvar2[]="string can also be initialized like this for the C++ Tutorial"; 

   Otherwise the string class provided in Standard Template Library can also be used. 

   There are some more obscure types too. For example, date. In C++ we cannot use date type right away. This has to be converted to a string or integer for outputs etc., Also, this data type is not available with all compilers. As of now, all of the windows C++ compilers provide this type. We'll deal with this date separately in another C++ Tutorial.

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us