C Programming language

adplus-dvertising
Day 1: Secondary data types, Primitive and Non-primitive data types
Previous Home Next
Primitive data types

Built in data type is called as primitive data types. The basic primitive data types in C are such as Character, (char); Integer (short int, int, long int, long long int); Floating-point number (float, double); Boolean; and etc.

Non-primitive data type

Example Integer, Float etc. An instance for non-primitive data type can not be created. A non-primitive data type is an abstract data type. Non-primrtive data types built out of primitive data types - linked list, queue, stack, etc.

Secondary data types
  1. Array

    An array in C language is a collection of similar data-type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int, float, and char. So an integer array can only hold integer values and cannot hold values other than integer.

    Types of Arrays

    1. One Dimensional Array
    2. Two Dimensional Array
    3. Multi Dimensional Array
    type var_name[size]
     
  2. Structures

    We used variable in our C program to store value but one variable can store only single piece information (an integer can hold only one integer value) and to store similar type of values we had to declare many variables. To overcome this problem we used array which can hold numbers of similar data type. But array too have some limitations, like in our real world application we deal with set of dissimilar data types and single array cannot store dissimilar data.

    For example

    Think about storing book information or product information, a product can have different information to store like product code (an integer), product name (a char array), product price (a float) etc. And to store 20 products information we can declare integer array for product code, 2D character array for storing product name and float array to store product price. This approach definitely achieves your goals, but try to consider these things too. What if you wanted to add more products than 20, what if you want to add more information on products like stock, discount, tax etc? It will become difficult to differentiate these variables with other variables declared for calculation etc.

    To solve this problem C language has a unique data type called Structure. C structure is nothing but collection of different related data types. If we are using C structure then we are combining different related data types in one group so that we can use and manage those variables easily. Here related data type means, a structure holding information about book will contains variable and array related to book.

    struct structure_name 
    { 
    	data type member1; 
    	data type member2; 
    	
    	
    };
    
  3. Pointer

    In C a pointer is a variable that points to or references a memory location in which data is stored. By usimg the pointer we change the content of the memory location.

    Pointer Declaration

    A pointer is a variable that contains the memory location of another variable. The asterisk tells the compiler that you are creating a pointer variable. Finally we have to give the name of the variable.

    // Syntax  
    type * variable name;
    
    // e.g.
    int *ptr; 
    float *string
Previous Home Next