Friday, 11 July 2014

Malloc

  1.  Malloc will be defined in the stdlib.h or malloc.h depending on the operating system we  use.
  2. Malloc does not reset the bits to zero
  3. malloc returns null if memory cannot be allocated
Calloc

  1. Calloc allocates the memory based on the two parameter. second parameter says how much memory should be allocated and first how many memory like that to be created,
  2. calloc(count,sizeof(individual))
  3. c in calloc stands for clear or count
  4. Calloc reset all the bits to zero
  5. Calloc returns null if memory cannot be allocatedEE
Realloc

  1. If developer wish to increase or decrease the size, one can use the realloc function
  2. The content of the previous value will be left unchanged
  3. If ptr is null then reealloc function will work as same of malloc function.
  4. reallloc can create the memory at different place and copy the content.

Friday, 4 July 2014

still intializing the variable using the equal sign.

 C++03 standard introduced the new way of intializing the variable.

You can use the paranthesis to initialize the variable now.

#include<iostream>
int main()
{
   
    int n(88);
    std::cout<<n;
   
    double d(512.5415);
    std::cout<<d;
   
   
    return 0;
}


In c++11 standard you can use curly braces to initialize the variable.


#include<iostream>
int main()
{
   
    int n{88};
    std::cout<<n;
   
    double d{512.5415};
    std::cout<<d;
   
   
    return 0;
}

Tuesday, 1 July 2014

array type has incomplete element type

PROGRAM

#include<stdio.h>

int main()
{

    int arr[][]= { {1,2}, {3,4}} ;

    printf(":: %d :: %d ",arr[0][1],arr[1][1]);


    return 0;
}





ERROR STATEMENT GCC

error: array type has incomplete element type


EXPLANATION:

The size of the two dimensional array cannot be initialized when initializing the value for the two dimensional array.




For eg:

int arr[]={1,2,3,4} // valid

int arr[][]={{15,3},{62,5}}; // Not valid in c and c++
int arr[][10]={{1,3},{852,5}}; // valid in c and c++


In more general, the multi dimensonal array size should be mentioned even though we are intialzing the array at the time of declaration.


But the 1st dimension can be left uninitialized.