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.
Pointers and arrays have a close relationship in the C programming language. In fact, arrays can be thought of as a kind of pointer.
An array is a contiguous block of memory that stores multiple elements of the same data type. The elements in an array are accessed using an index that represents their position within the array. When an array is declared, the name of the array acts as a constant pointer to the first element of the array.
Pointers, on the other hand, are variables that store memory addresses. They can point to the address of another variable or object. In the case of arrays, a pointer can be used to access elements of the array.
To illustrate the relationship between pointers and arrays, let's consider an example:
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr; // Assigning the address of the first element to the pointer
printf("Array elements using array syntax:\n");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
printf("\nArray elements using pointer syntax:\n");
for (int i _________ ___ _____ _____ _______.
_______ ____ _______ _________ _____ ______.
_______ _____ ____ ________ _________ ________ _______ ____ _____ ______ _________ ___.
____ _____ _______ _____ _______.
_____ ______ ______ ______ ______ ____ _________ ________.
_______ _____ ____ _______ ________ _________ ______ ________ _____ ____.
_______ _______ ______ ______ _____ ________ __________.
___ ___ ____ ________ _________ _______ _________.
___ ________ ______ ______ _____ ________ _____.
____ ________ ___ __________ ______ ______ __________.
______ _____ ___ _________ ____ ____ ______ ___.
________ ____ _________ _________ ______ ___ ____.
_______ ____ ________ _______ _________ __________ _____ ________ ___ __________ _______.
______ _________ _________ _____ ___ _________.
________ _____ ___ ______ _______ ______ ________ ______ _____ ____ ______.
____ _______ ________ ________ ____ ________ ___ ________ _____ __________.
____ _______ __________ ______ ________ ________ ________ ___ _____ _________ ___ ________.
_______ ____ ______ _______ ___ _______ _________.
___ ___ ______ _____ _____ ________ _______ _________ ____.
__________ ______ ___ _______ ____ __________ _________ ______ _____ _______ ________.
____ ____ ____ _________ __________ ______.
___ _______ __________ _____ ____ ____ ____ _________ _______ ______ _______.
____ __________ __________ ___ ____ _________ _______ _______ _____ ________ ____ ________.
___ _____ ______ ____ ___ _________ _____ ___ ________.
________ ________ _________ ______ _______ _______ ______ __________ __________ ____ _________.
___ _________ ___ _____ _________ ____ _________ _______ ________.
____ ________ ______ _________ _________ ____ _________ ____ _________ __________ ____.
____ _______ ______ ___ ____ ______ ________ __________ _____ ______ ____.
_____ ______ ________ ___ _______ ___ _______ _____ ___.
_______ _________ _______ ______ ______ ___ _______ _____ ___ _________ _______.
____ ____ _______ ______ _______ _____ ____.
__________ _____ _________ ______ ________.
_________ __________ _________ __________ _____ ________.
_____ _______ ____ ___ _________ ____.
________ ___ ___ _______ _______ ____ __________.
_________ ___ _____ __________ _____ _____.
________ ____ _____ ______ ________ ___.
_____ ____ ___ _______ _________ __________ __________ ________.
_____ __________ _______ ______ ______ ______ _____ ____ _______ _________ _____ _________.
____ _____ _____ _______ ___ ___ __________ _______.
____ __________ ____ ______ __________ ___ _______ _________ _______ ______.
_______ ___ ______ _______ ________ ______.
______ _______ ____ _________ ________ ____ ________ ______ _______ ______ ______ __________.
________ ______ ___ _____ __________ ___ _____ ____ __________ __________ ________ ___.
_________ _____ ______ ____ ___ ______ ____ _______ _______ _____.
________ _______ __________ ________ _________ __________ ______ _______.
_____ ______ ________ __________ ______ ____.
__________ ________ ______ _____ ___ _____ _________ ____ _____ __________ ______ _______.
_____ __________ _________ ________ ____ _____ _______ __________ _________ ______ ____ ________.
__________ ________ _____ _______ __________ __________ ________.
______ _________ ______ __________ _________ _____ _________ __________ _____ __________ _______ ___.
_______ _______ ________ __________ __________.
_____ _______ ___ _________ ______ _______ _____.
______ _____ __________ __________ ____ _________ ____.
______ ____ __________ _______ _________ __________ ___ __________.
_________ ______ _________ ________ _______ _______ _____ _______ __________ _____ ______ ________.
__________ ____ ______ ________ __________.
___ ______ _______ _____ ______ ______ ______ _____.
__________ ______ _______ _____ ______ ____.
_________ ______ ___ ______ ________ _______ __________ ______ _________ ____ __________.
____ _______ ________ _____ ________ ____ _______ ________ _______.
_______ __________ ______ _______ ________ ____ ________ _________ ________ ____ ______.
______ _______ _____ __________ __________ __________ _____ ________ _______ ____ _______ _______.
____ ___ ___ ___ _____ _______.
_________ ______ _______ _______ _________ ___.
_________ ______ ______ _______ ________ ______ ________ ___ ________ _________ _____ ____.
___ ______ _____ _____ ______ ____ _______ ___ _______.
_________ ______ ______ _____ ____ _____ ______ ____ ______ ______ _____.
_______ _____ ____ ________ _________.
_________ __________ __________ ____ _______ ___ __________ __________ _______ _________ ________.
________ _______ ____ _________ ___ _______ ____ _________ _______.
________ ______ ____ _________ _____ ______ _______ __________ ___.
__________ _________ ________ ______ _______.
_____ ______ _____ _________ ____ _________.
Get Full Answer on WhatsApp