Briefly discuss the relation between pointers and arrays, giving suitable example. Write a program in C, to print transpose of a 2D matrix entered by a user. Also give comments.
In programming languages like C and Python, pointers and arrays have a closely intertwined relationship. While Python handles arrays differently than C, it’s important to understand how the concept of pointers works in C and how it relates to arrays.
### Relation between Pointers and Arrays in C:
In C, arrays and pointers are closely related. An array is essentially a block of contiguous memory locations, and a pointer is a variable that stores the address of another variable, including the address of the first element of an array.
When we declare an array in C, for example:
```c
int arr[5] = {1, 2, 3, 4, 5};
```
Here, `arr` is not just an array but also acts like a pointer to the first element of the array. In fact, the name of the array `arr` is equivalent to a pointer to the first element of the array. This means that the expression `arr` is pointing to the first element of the array `arr[0]`.
In C, we can use pointers to access elements of the array. For example:
```c
int *ptr = arr; // Pointer ptr ___ ___ _________ _______ ________ ___ _____ ___.
_____ _____ ___ ______ ____ _____ _______ ____ ______ ___ ___ ___.
_____ _______ __________ _____ ____ ______ ________ _____ ________ __________ _____.
_______ _______ ___ ____ ____.
______ _________ _____ _________ ___ ____ _______ ___ ______ __________.
_____ _______ _________ _______ _____ ____ ______ ____.
_______ ________ ___ _____ _________ _____ _____ ___.
______ _____ _________ ___ ____ ___ _____.
___ _________ _________ _____ ________ ________.
_______ ________ _______ ___ ___ ____ __________.
____ _____ _______ ___ _______ _______ ___ ___ ______ _________ ________ ________.
_____ _____ _________ ________ ___.
_________ _________ ___ _____ ________ __________ _________ _______ ________ ____.
__________ __________ ___ _________ ____ ___ __________ _________.
__________ ________ _________ ________ __________ _____ ___ ____ ____ ________.
__________ ______ ________ _____ _______.
__________ _____ _______ ________ ______ _________ _____ ___ __________.
_____ _____ ____ _________ ____ ____ _____ _____ _________.
_________ _______ ________ ________ _______ ________ ___ ______ ______ __________ ________ ___.
_____ ___ __________ ______ ________ ________ _______ ________ ____ _____ ____.
_______ _____ ________ ___ _______ _________ __________ ___.
_____ ___ ________ __________ ____ _____ ____ ___ _____.
___ ____ __________ __________ ____ ______ ____ __________ _______.
______ _________ ______ ________ _________ __________ ______ __________ ______ ________ __________.
___ ________ ______ _________ _______ ______ ___ ______ ________ __________ _______ ______.
_______ ________ __________ ________ _________ ____ __________ ___ ____ ______ ______.
_______ _________ _____ ______ _________ ________ _____ ______.
_________ _______ _____ _________ ____ ________ ______ _______ ____.
____ ______ _____ _____ ________ _____ _____.
____ __________ _______ _________ ___.
_____ _______ _______ __________ ________ ______.
________ ________ _____ _______ ______.
_______ _____ ____ _____ _______ _________ __________ ___ _______ ______ ____ __________.
___ ____ __________ _________ _______.
__________ __________ _____ ____ ____ ________.
___ _______ ______ _____ ___.
______ _______ ___ _______ _______ _______.
_____ ___ __________ ________ ____ _______ _________ ________.
________ _________ _______ __________ _________ __________ ______ _________ _______.
____ ______ __________ ______ __________ __________ _____ ______ ____.
____ _____ __________ ___ ________ ___ ________ ___.
______ ___ _________ ___ _______ ____ ______ _____ ______.
__________ _________ _______ ___ ______ ___ ____ __________ ______ _____ _________.
____ ________ ______ _________ ___.
_____ __________ __________ ______ _____ ___ ________ ________.
___ _________ _____ ______ ___ _____ _______.
_____ _________ _______ _____ _______ ____ _____.
__________ _______ ____ _________ ______ ____ _______ __________ _____ _____.
_________ ________ _________ _________ _____ _______ _________ ___ ______ _____.
_____ ________ __________ ___ _________ ___ ________.
_____ ___ ______ _________ _______ _______ _________ ________ _____ _________.
___ _________ ____ ____ ______.
_____ ______ __________ ___ ____ ______ _______ ___.
__________ __________ __________ ___ _________ _________ _____ ___ ________ ________.
____ ________ _______ _____ ____ __________ ______ ______ ___ ___ _________ ___.
______ ___ ______ ____ ________ _________ __________ __________ _________ _________ _________ ___.
___ ________ _______ ________ _________ _____ __________ ____ _________ ____.
________ ___ _____ _____ _______ ______.
______ __________ _____ ___ ___ ___ _____ ____ _______ ______.
______ _______ ______ __________ _______ __________ _____ __________ _______ ________ ____.
________ ______ ____ ________ ____ ____ ______ ____ ___ _________ _______.
__________ ___ _______ _______ ____ ______ __________ ______ _________ __________.
____ ______ _____ ______ ____ _________ _______ _________ _________ _______ __________.
__________ ______ __________ _____ ____ ________ _________ ___ _______ ________ ________.
___ __________ ___ ___ ____ ______ __________ _______.
_______ ________ _____ ____ ___.
_____ ____ _____ __________ _________ _________ __________ _____ ______ _______ _______.
________ _______ ____ ______ ______ _______ _______ _________.
___ _____ _________ ___ _______ ________.
_____ __________ ____ ____ _________ ____.
_______ ______ _____ _________ _________ ______ ______ __________ ______ _____ ______.
____ ______ __________ _______ ________ ________ ____ __________ _________ _________ __________.
_______ __________ _________ _____ ____.
_________ ________ _____ _______ _____ _____ _________ ______ _______ _________.
_________ ____ _____ ___ _________ ______ __________ __________ ____ ____ _____.
____ ________ __________ _____ ____ ______.
_______ ___ _________ _____ ___ ________ _________ __________.
_________ ____ _________ ____ __________ _________ ________ ____ __________.
______ ___ ______ _____ ___ _____ __________ _______ ________ ________.
_____ ______ __________ _____ _____ _______ ____.
__________ __________ __________ ______ _____ ___ _____ ______ ______.
______ ___ __________ __________ ____.
____ __________ ______ ____ _______ _______ ______ ____ ______.
___ ___ _______ ________ ___ _____ _____ _____ _________.
__________ ________ _____ _____ _________ __________ ______ __________ ______ _________ _______ ___.
______ ____ _____ ________ ___ __________ _________ ____.
___ _______ __________ ________ _________ ___ _____ ______.
_______ ___ ______ ______ __________.
__________ _______ ________ __________ _________ _____ ____ _______ _____ ______.
___ _______ _________ _____ _______.
_____ _______ _____ ________ ________ __________ ________.
______ _________ ________ ___ ____ ________ __________ ______ ____ ________ __________ _______.
_____ _________ _______ __________ ________ __________ ____ __________ __________ _________ _______.
___ ______ _______ _______ _____ ________ _______ ________ ___ ____ ______.
_____ __________ ______ _______ ___ ________ ________ _______.
____ _________ ______ ________ ___ _______ __________ _______ __________.
_________ __________ _____ ______ ______ __________ _____ ______ ______ ___ _____.
____ __________ ________ ________ ______ ___ ____ ___ __________ ___.
___ ________ __________ _____ _______ __________ _______ ________ ______.
____ ____ ______ ___ ______ ____ __________ _______ ________ ______ _____.
________ ______ ____ ________ ______ __________.
___ ________ ___ _____ ______ _________ _______ ___ __________ ______ ________.
________ _________ _____ _________ ___ _______ _________ ___ ______ _________ ________.
__________ _________ _____ _______ _____.
_________ ______ ____ ______ _____ ___ _____ __________.
___ _______ __________ ____ _______ ______ _____ _______ ___ ________ __________.
___ _____ _____ ____ ___ ____ ___ ___ _____.
__________ __________ ________ _________ _______ ___ _______ _______ _____.
_______ ____ ______ __________ _____ _______ ______ _____ ________ ___ __________.
_________ __________.
Get Full Answer on WhatsApp