Concept Of C++ Data Types

25,432 views
25,125 views

Published on

it's about the data types used in c++ as given in class XI text.............

Published in: Education, Technology, Business
3 Comments
13 Likes
Statistics
Notes
No Downloads
Views
Total views
25,432
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
970
Comments
3
Likes
13
Embeds 0
No embeds

No notes for slide

Concept Of C++ Data Types

  1. 1. CONCEPT OF C++ DATA TYPES<br />MADE BY:-<br /> RAFIYA SIRIN<br />XI-B<br />
  2. 2. DATA TYPES<br />Data types are means to identify the type of data and associated operations of handling it. C++ provides a predefined set of data types for handling the data it uses. When variables are declared of a particular data type then the variable becomes the place where the data is stored and data types is the type of value(data) stored by that variable. Data can be of may types such as character, integer, real etc. since the data to be dealt with are of may types, a programming language must provide different data types.<br />
  3. 3. FUNDAMENTAL DATA TYPES<br />DATA TYPE MODIFIERS<br />DATA TYPES<br />DERIVED DATA TYPES<br />USER DEFINED DATA TYPES<br />
  4. 4. INTEGER<br />CHARACTER<br />FUNDAMENTAL DATA TYPES<br />FLOAT<br />FUNDAMENTAL DATA TYPES ARE THOSE THAT ARE NOT COMPOSED OF OTHER DATA TYPES<br />DOUBLE<br />VOID<br />
  5. 5. INTEGER DATA TYPE<br />Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values. <br />
  6. 6. CHARACTER DATA TYPE<br />It can store any member of the C++ implementation&apos;s basic character set. If a character from this set is stored in a character variable, its value is equivalent to the integer code of that character. Character data type is often called as integer data type because the memory implementation of char data type is in terms of the number code.<br />
  7. 7. FLOAT DATA TYPE<br />A number having fractional part is a floating- point number. An identifier declared as float becomes a floating-point variable and can hold floating-point numbers. floating point variables represent real numbers. They have two advantages over integer data types:-<br />1: they can represent values between integers.<br />2: they can represent a much greater range of values.<br />they have one disadvantage also, that is their operations are usually slower.<br />
  8. 8. The data type double is also used for handling floating-point numbers. But it is treated as a distinct data type because, it occupies twice as much memory as type float, and stores floating-point numbers with much larger range and precision. It is slower that type float.<br />DOUBLE DATA TYPE<br />
  9. 9. VOID DATA TYPE<br />It specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared. It is used when program or calculation does not require any value but the syntax needs it.<br />
  10. 10. INTEGER TYPE MODIFIERS<br />DATA TYPE MODIFIERS<br />CHARACTER TYPEMODIFIERS<br />THEY CHANGE SOME PROPERTIES OF THE DATA TYPE<br />FLOATING-POINT MODIFIERS<br />
  11. 11. INTEGER TYPE MODIFIERS<br />C++ offers three types of integer data type:-<br />1:- short integer- at least two bytes.<br />2:- int integer – at least as big as short.<br />3:- long integer-at least four bytes.<br /> the prefix signed makes the integer type hold negative values also. Unsigned makes the integer not to hold negative values.<br />
  12. 12.
  13. 13. CHARACTER TYPE MODIFIER<br />The char can also be signed or unsigned. unlike int,char is not signed or unsigned by default. It is later modified to best fit the type to the hardware properties.<br />
  14. 14. FLOATING POINT TYPE MODIFIERS<br />There are three floating-point types: float, double, and long double. These types represent minimum allowable range of types.<br />Note:- don’t use commas in numeric values assigned to variables.<br />
  15. 15.
  16. 16. ARRAYS<br />FUNCTIONS<br />DERIVED DATA TYPES<br />POINTERS<br />REFERENCES<br />CONSTANTS<br />
  17. 17. ARRAYS<br />An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.That means that, for example, we can store 5 values of type int in an array without having to declare 5 different variables, each one with a different identifier. Instead of that, using an array we can store 5 different values of the same type, int for example, with a unique identifier.<br />Like a regular variable, an array must be declared before it is used. A typical declaration for an array in C++ is:type name [elements];<br />NOTE: The elements field within brackets [ ] which represents the number of elements the array is going to hold, must be a constant value, since arrays are blocks of non-dynamic memory whose size must be determined before execution. <br />
  18. 18. VALID OPERATIONS WITH ARRAYS:-<br />billy[0] = a;<br />billy[a] = 75;<br />b = billy [a+2];<br />billy[billy[a]] = billy[2] + 5;<br />PROGRAM:-  <br />// arrays example<br />#include &lt;iostream&gt;<br />using namespace std;<br /> int billy [] = {16, 2, 77, 40, 12071};<br />int n, result=0;<br />int main () OUTPUT:- 12206<br />{<br /> for ( n=0 ; n&lt;5 ; n++ )<br /> {<br /> result += billy[n];<br /> }<br /> cout &lt;&lt; result;<br /> return 0;<br />}<br /> <br />
  19. 19. FUNCTIONS:-<br />Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by it self. Instead its requests other program like entities – called functions in C – to get its tasks done. A function is a self contained block of statements that perform a coherent task of same kind.<br />The name of the function is unique in a C Program and is Global. It means that a function can be accessed from any location with in a C Program. We pass information to the function called arguments specified when the function is called. And the function either returns some value to the point it was called from or returns nothing.<br />We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind.<br /> We first declare the function and then at the end of the program we define the function.<br />
  20. 20. POINTERS:-<br />The memory of your computer can be imagined as a succession of memory cells, each one of the minimal size that computers manage (one byte). These single-byte memory cells are numbered in a consecutive way, so as, within any block of memory, every cell has the same number as the previous one plus one.This way, each cell can be easily located in the memory because it has a unique address and all the memory cells follow a successive pattern. For example, if we are looking for cell 1776 we know that it is going to be right between cells 1775 and 1777, exactly one thousand cells after 776 and exactly one thousand cells before cell 2776.<br />The general form of declaring the pointer is <br /> type*ptr;<br />
  21. 21. REFERENCES:- <br />It is an alternative name for an object. A reference variable provides an alias for a previously defined variable. It’s declaration consists of a base type, an &(ampersand), a reference variable name equated to a variable name. <br /> the general form of declaring is:-<br /> type&ref-var = var-name;<br />
  22. 22. CONSTANTS:-<br />C++ constants are not very different from any C++ variable. They are defined in a similar way and have the same data types and the same memory limitations. However, there is one major difference - once a constant has been created and value assigned to it then that value may not be changed.<br />Defining Constants with C++<br />There are actually three ways of defining a constant in a C++ program:<br />by using the preprocessor<br />by using the const key word<br />by using enumerators - these will have a range of integer values<br />It&apos;s also worth noting that there are two types of constant: literal and symbolic. <br /> the general form of declaring a variable is:-<br /> const int upperage = 50;<br />
  23. 23. CLASS<br />STRUCTURE<br />USER DEFINED DERIVED DATA TYPES<br />UNION<br />ENUMERATION<br />
  24. 24. CLASS<br />Class: A class is a collection of variables and function under one reference name. it is the way of separating and storing similar data together. Member functions are often the means of accessing, modifying and operating the data members (i.e. variables). It is one of the most important features of C++ since OOP is usually implemented through the use of classes. <br />
  25. 25. Classes are generally declared using the keyword class, with the following format:<br />class class_name { access_specifier_1: member1; <br />access_specifier_2: <br />member2; ... <br /> } object_names;<br />
  26. 26. STRUCTURES:-<br />A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths.<br />Data structures are declared in C++ using the following syntax:struct structure_name {member_type1 member_name1;member_type2 member_name2;member_type3 member_name3;..} object_names;<br /> where structure_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.<br />Structure is different from an array in the sense that an array represents an aggregate of elements of same type whereas a structure represents an aggregate of elements of arbitrary types..<br />
  27. 27. UNION:-<br />Unions allow one same portion of memory to be accessed as different data types, since all of them are in fact the same location in memory. Its declaration and use is similar to the one of structures but its functionality is totally different:<br />union union_name {<br /> member_type1 member_name1;<br /> member_type2 member_name2;<br /> member_type3 member_name3;<br /> .<br /> .<br /> } object_names;<br />All the elements of the union declaration occupy the same physical space in memory. Its size is the one of the greatest element of the declaration. <br />all of them are referring to the same location in memory, the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent of each other.One of the uses a union may have is to unite an elementary type with an array or structures of smaller elements. <br />The exact alignment and order of the members of a union in memory is platform dependant. Therefore be aware of possible portability issues with this type of use.<br />
  28. 28. ENUMERATION:-<br />It can be used to assign names to integer constants. <br /> //Program to illustrate Enumerator<br /> #include&lt;iostream.h&gt;<br /> void main(void)<br /> {<br />enum type{POOR,GOOD,EXCELLENT};//this is the syntax of enumerator<br /> <br /> int var;<br /> var=POOR;//this makes programs more understandable<br /> cout&lt;&lt;var&lt;&lt;endl;<br /> var=GOOD;<br /> cout&lt;&lt;var&lt;&lt;endl;<br /> var=EXCELLENT;<br /> cout&lt;&lt;var;<br /> }<br />//poor=0<br /> good=1<br /> excellent=2<br />
  29. 29. CONCLUSION:-<br />We have so many data types to allow the programmer to take advantage of hardware characteristics. Machines are significantly different in their memory requirements, memory access times, and computation speeds.<br />
  30. 30. THANK YOU<br />

×