Difference between arrays and pointers

05 min read

Difference between Arrays and pointers

  • An array is a collection of elements of similar data type whereas the pointer is a variable that stores the address of another variable. 
  • An array size decides the number of variables it can store whereas; a pointer variable can store the address of only one variable in it.
  • Arrays can be initialized at the definition, while pointers cannot be initialized at the definition.
  • Arrays are static in nature which means once the size of the array is declared, it cannot be resized according to users requirement. Whereas pointers are dynamic in nature, which means the memory allocated can be resized later at any point in time.
  • Arrays are allocated at compile time while pointers are allocated at runtime.
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error