Question

How would you differentiate between the terms pointer to an array and array of pointers? Give proper examples.

26 Feb 2024
Answer :
Word Count : 437

The terms "pointer to an array" and "array of pointers" refer to different concepts in C programming, distinguished by how they are declared and used.

1. **Pointer to an Array**:
   - A pointer to an array is a pointer variable that points to the first element of an array.
   - When you have a pointer to an array, you can access elements of the array using pointer arithmetic.
   - The pointer to an array points to the memory address where the array is stored.
   - Example:
     
     #include <stdio.h>

     int main() {
         int arr[5] = {1, 2, 3, 4, 5};
         int (*ptr)[5];  // Pointer to an array of 5 integers
         ptr = &arr;     // Assigning the address of arr to ptr

         printf("First element of array: %d\n", (*ptr)[0]); // Output: 1

     

__________ ____ _____ _______ _________ __________ _____ ___.
____ _____ ____ _____ _____ _________ ______ _______ __________ ____ _________.
_______ __________ ______ _________ ________ ___ _____ ____ ______ _____.
_______ __________ _____ ___ _______ ___.
_______ ___ _____ ______ ____ __________ ___ __________ _________ ________ ______.
____ ___ _____ ______ ______ ____ _____ ___.
_______ ________ __________ ___ ____ __________ ____ ________ _______.
________ __________ ____ ________ ____ ___ ________ ___ __________ _______.
_____ ____ ___ ______ ___ __________.
________ _______ __________ ________ _____ _________ ________ ____ ____.
________ _______ ___ ______ ________ __________.
______ ________ ___ ________ ______ __________ ________ ______ _________ ___.
_________ ___ _______ ______ ____ ___ __________ ____ ____ ____ ___.
______ __________ __________ __________ __________ _____.
__________ _____ _________ ____ __________ ____ ________.
______ ___ ________ _______ _____ ___ _________ ____ _______ __________ ____.
__________ ____ ______ ____ __________ ______ _____.
_______ ____ ____ __________ ________ ______ _____.
_______ __________ ________ _______ _________ ___ ____ ______ __________ ________ _______.
_____ _________ __________ ________ ___ _________.
______ _____ ____ _____ _____ _____ _________ _____ _________ ________ ________.
______ __________ __________ ________ __________.
_____ _____ __________ ________ ______ ___.
___ ____ ________ _______ ____ _____ _______.
_____ _____ ____ _______ ______ ___.
__________ ___ _______ _____ ____ _____.
____ ________ _______ __________ ________ __________ _______ ______ ________ _______.
______ _____ __________ __________ ________ __________ ____ _________ _______ ________ _____.
___ _____ __________ __________ _________ ____ ____ _______ _______ ________ _______ _________.
________ ______ ____ ______ _________ ____ ______.
______ _______ ___ _________ _______ ________ _______ ______ ____ _________ _________ ________.
_______ ________ ___ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MMT 1 2024 - How would you differentiate between the terms pointer to an array and | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→