Showing posts with label Data Handling. Show all posts
Showing posts with label Data Handling. Show all posts

Saturday, 24 September 2011

User defined datatypes

There are some derived data types which are user defined. Examples of these data types are : Class, structures, unions and enumerations. Thogh we will have a detailed discussion of these topics in the coming tutorials. But let us a short review of these topics.

  1. Class:
  2. A class is a group of similar or dissimilar elements that are referenced under the same name. The variables under these names may be different. For example, consider this:
    class student
                              {
                                   int roll_no;
                                   char name;
                                   float percentage;
                                   char subjects 
                              };
    
    
    In this example we see that this class student contains four dissimilar elements under the same name, i.e 'student'. All these four elements are of different types such as roll_no of int type, name of character type and so on.
  3. Structures :
  4. Structure is very similar to class. This is also a collection of similar or dissimilar elements which are referenced under the same name. Now there arises a question in your mind. What is the need to tell about structures when it is very similar to class. Yes you are right it is very similar to class. But there is a little difference between them. They differ by visibility modes. We will discuss about the visibility mode in details when we will study about classes and structures. An example for structure can be given as
    structure student
                              {
                                   int roll_no;
                                   char name;
                                   float percentage;
                                   char subjects 
                              };
    

Thursday, 22 September 2011

Data types


In both the programmin languages, i.e C and C++ we use data types. Data types are the tools to identify the type of data and the operations to which it undergoes. In C and C++, there are two types of data types:
  1. Fundamental datatypes
  2. Derived datatypes
  • Fundamental datatypes:  The datatypes which are known as the root of all datatypes are called fundamental datatypes. There are basically five types of fundamental datatypes which can be listed below as:
    1. int data type : When ever we declare any identifier as int type, it becomes an integer variable. For example: If we declare int value then the identifier or variable vlaue will become an integer type data variables. What does this simply specify ? It specifies that the variable value can now store and reveal only integer values or simply it can operate only on integer values.
    2. char datatype: When ever we use char before any specifier, it becomes character type variable. This can be explained with the help of an example. Suppose: char words, now this variable word will become character type, i.e now it can store and reveal or can operate with all data of character type.
    3. float datatype: This datatype when used before any specifier, converts that specifier into a variable of floating type variables. What does this mean ? This means that now that variable can store and reveal or can operate with numerical values that contains digits after decimal.
    4. double datatype: This datatype works similar to float datatype. The only difference is that it can deal with numbers having more places after decimal with minimum chances of error.
    5. void datatype: Void datatype is simple datatype that is used to make any varialbe(mostly functions) which do not retun any values. Example: void main ()
  • Derived Data types : These data types which are derived or originated from default data tpye or fundamental data types. Such type of datatypes are called Derived datatypes. Example of Derived datatypes are : Arrays, Function, Pointer, Reference. We will be discussing about all these topics and programs in detail in the coming tutorials.