Question

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. Support your program with suitable comments.

07 Mar 2024
Answer :
Word Count : 429

Pointers and arrays have a close relationship in C programming, as arrays can be accessed using pointers and vice versa. In C, an array name often behaves like a pointer to the first element of the array. When you use the array name, it gets converted into a pointer to the first element.

Consider the following example:

```c
#include <stdio.h>

int main() {
    int arr[3] = {1, 2, 3};
    int *ptr = arr; // ptr points to the first element of arr
    
    printf("First element of arr using array syntax: %d\n", arr[0]);
    printf("First element of arr using pointer syntax: %d\n", *ptr);
    
    return 0;
__________ __________ ________ _________ __________ _________ ____ ____ __________ ___.
__________ __________ ____ ______ _____ __________ _______ ____ ______ ________.
_____ ______ ______ ________ ________ _____ _______ _________.
___ _________ ______ ____ ______ _______ __________.
______ _________ ____ __________ ___ ____ _____ __________ ________ __________.
_________ _________ ___ ______ ___ ___ _______ ________ ____ ________.
____ ______ ____ __________ ____ ______ _________ _____ ________ _________.
_________ ___ _________ _______ _______ ______ _______ _________.
__________ _______ __________ ____ _________ ________ ____ __________.
__________ _____ _________ ___ ________ ____.
__________ ____ ____ ______ __________ _______ __________ _____ _____ ________.
___ ____ ____ _______ ________ _______ ___ __________ ___ ________ _____.
_______ _______ _____ _____ ____.
___ _______ _____ ___ ______ __________.
____ _________ ______ ________ ________ __________ ___ _______ ________ ______ ____.
______ _____ _______ ____ _________ _______ __________ _________.
___ _____ _____ ________ ___ ____ _________ _________.
______ _______ __________ ___ _________ ________ ________.
_______ ________ ________ ___ __________ ________ _____.
___ ___ ____ ________ _______ __________ _____ __________ ____ ___ _______ ______.
_________ ____ ____ __________ ________ _______ __________ ___ ___ ______.
_________ ________ ____ ____ ________ _____ ____.
____ ____ ____ __________ _______.
_______ ____ _________ ________ _______ _____.
________ ______ ________ ___ ____ _____ ________ __________.
______ ______ _____ ______ _________ _________ _______ ________.
_______ ___ ___ ______ ______ ______ _________.
______ _____ _____ ___ ________ _______ ______ ___ _____.
_____ ____ _______ _____ __________.
_________ ___ ______ ___ _______ _________ __________ _______ _______.
____ ____ ___ _______ ____ _____ __________ ______.
_______ ______ ____ _________ __________ __________ ___ ________ ____ _______ ____ ____.
___ _______ _____ _________ ______ __________ ___ _________ _______ ________.
_____ __________ _________ ____ _________ ___ ____.
__________ _____ ____ ________ _____ ________ ________ ______ _____ _____.
______ ________ _______ __________ __________ ___ _______ _____ _________ ____ ____.
__________.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top