Knowee
Questions
Features
Study Tools

Distinguish between Array and Pointers

Question

Distinguish between Array and Pointers

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step by step distinction between Arrays and Pointers:

  1. Definition:

    • Array: An array is a collection of items stored at contiguous memory locations. The items are of the same data type.
    • Pointer: A pointer is a variable that stores the memory address of another variable.
  2. Memory Allocation:

    • Array: Memory allocation for an array is done at compile time, which means the size of an array is fixed.
    • Pointer: Memory allocation for a pointer is done at runtime, which means the size can be changed.
  3. Flexibility:

    • Array: Arrays are less flexible as you cannot change the size or the data type of elements once it is declared.
    • Pointer: Pointers are more flexible as they can point to any type of data and also the memory block size can be changed at runtime.
  4. Element Access:

    • Array: Elements in an array can be accessed directly by their index.
    • Pointer: Elements in a pointer need to be accessed by dereferencing the pointer.
  5. Arithmetic Operations:

    • Array: Arithmetic operations cannot be performed on arrays.
    • Pointer: Arithmetic operations can be performed on pointers.
  6. Value Modification:

    • Array: The whole array can be passed to a function, but the changes made to the array elements in the function do not reflect in the original array.
    • Pointer: A pointer can be passed to a function and the changes made to the value pointed by the pointer in the function reflect in the original value.
  7. Keyword Usage:

    • Array: The '[]' is used to declare an array.
    • Pointer: The '*' is used to declare a pointer.

This problem has been solved

Similar Questions

A two dimensional array can be defined as a one dimensional array of pointers

Which of the following statements about arrays in C is not true:Group of answer choicesA function that receives as array argument must also always receive a buddy variable indicating the size of the arrayA function that receives an array argument may manipulate it using either pointer de-referencing (the * operator) or using array indexing (the [] operator)A function that receives an array argument has the ability to alter the values of the elements in the arrayA function that receives an array argument can then pass that array to another function that it callsA function can receive multiple array arguments

Q1: Which of the following statements about arrays in C is not true:The first element in the array is at index 0The array name is a pointer constantAll of the elements in the array are of the same typeAn array must always have an associated buddy variable to indicate its sizeAn array can be of any type

Which of the following can be modified by a function when a pointer to it is passed?Marks : 1Negative Marks : 0Answer hereThe pointer's memory addressThe data the pointer points toThe size of the data the pointer points toThe number of elements in an array pointed to by the pointer

Q2: Suppose that A is an array of int, and that B is declared to be a pointer of type int *. Which of the following is not a valid assignment statement, assuming that both B and the elements of A have been initialized to suitable values:B = A;B = &A[3];B = *(A + 3);B = (A + 3);B = A + *A;

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.