Search PPTs

Thursday, July 25, 2013

PPT On C++ Data Types

Presentation On C++ Data Types
Download

C++ Data Types Presentation Transcript:
1.C++ Data Types

2.C++ Data Types
While doing programming in any programming language, you need to use various variables to store various information.
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
You may like to store information of various data type like character, wide character, integer, floating point, double floating point, boolean etc.
Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.

3.Primitive Built-in Types:

4.Several of the basic types can be modified using one or more of these type modifiers:
signed
unsigned
short
long
The following table shows the variable type, how much memory it takes to store the value memory, and what is maximum and minimum vaue which can be stored in such type of variables.

5.The sizes of variables might be different from those shown in the above table, depending on the compiler and the computer you are using.
Following is the example which will produce correct size of various data type on your computer.

6.#include
using namespace std;
int main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
 cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
 return 0;
}
 

7.This example uses endl which inserts a new-line character after every line and << operator is being used to pass multiple values out to the screen.
We are also using sizeof() function to get size of various data types.
When the above code is compiled and executed,
it produces following result which can vary from machine to machine:

8.Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 4
 Size of float : 4
Size of double : 8
Size of wchar_t : 4

9.Typedef Declarations:
You can create a new name for an existing type using typedef. Following is the simple syntax to define a new type using typedef:
typedef type newname;
For example, the following tells the compiler that feet is another name for int:
typedef int feet;
Now, the following declaration is perfectly legal and creates an integer variable called distance:
feet distance;

10.Enumerated Types:
An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration.
To create an enumeration requires the use of the keyword enum. The general form of an enumeration type is:
enum enum-name { list of names } var-list;
Here, The enum-name is the enumeration's type name. The list of names is comma separated.
For example, the following code defines an enumeration of colors called colors and the variable c of type color. Finally, c is assigned the value "blue".

No comments:

Related Posts Plugin for WordPress, Blogger...

Blog Archive