Question

Explain pointer arithmetic with example. Also explain advantages of malloc and calloc.

30 Nov 2017
Answer :
Word Count : 559

Pointer arithmetic is a fundamental concept in programming that involves performing arithmetic operations on pointers, which are variables that store memory addresses. It's commonly used in languages like C and C++ for various purposes, including memory management and array manipulation.

Here's an explanation of pointer arithmetic with an example:

Pointer Arithmetic:
Pointer arithmetic allows you to manipulate the memory addresses stored in pointers to access and modify data. It involves two main operations: addition and subtraction.

1. Addition: You can add an integer value to a pointer to move it to a new memory location. The size of the addition is determined by the data type the pointer is pointing to. For example, if you have an integer pointer `intPtr` pointing to an array of integers, you can move it to the next integer element like this:

```c
int* intPtr = someIntArray; // Points to the first element of an array of integers
intPtr = intPtr + 1; // Moves to the next integer element
```

2. Subtraction: You can subtract an integer value from a pointer to move it to a previous memory location. Again, the size of the subtraction depends on the data type. For instance:

```c
intPtr = intPtr - 1; // Moves back to the previous integer element

____ _____ ________ __________ _________ _____ ____ ______ ________ _____.
__________ ________ ___ _________ _________ _____.
_______ ___ ____ __________ ____ _________.
________ ________ _________ ______ _____ ___ ___ ________ _____.
__________ ________ ________ ____ __________ ___ ____.
_________ __________ __________ ________ ___ _________.
__________ ____ ___ __________ __________ _________ _______ ______ ___ _________ ___.
_________ _______ ________ _____ ______ __________ _____ ___ _______ _______ ___.
________ ___ ______ ______ ________ _______.
______ ________ ____ ______ __________.
_________ _____ ____ _____ __________ _______ ________ _____ _________.
____ __________ __________ _______ ____ ________ _______ ______.
_________ ___ ________ ______ _____.
________ _________ ________ __________ _________ _____ ________ ________ _______ ____ ________ _________.
______ ________ ______ _________ ______ ____ ________ ____ ________.
_____ _________ ___ ____ ___ _____ __________ __________ _________ ____ _______ _______.
_______ ___ ___ ________ ___ ___ _________.
____ _____ ____ __________ _________ _____.
________ _____ ________ __________ _____ _______ _______ ____ ________.
___ _______ ___ ___ ____ _____ __________ ________ _____.
_____ ______ __________ _____ ________ ___ _______ ___ ___.
_____ _____ _________ ______ _______ _______ ________.
_________ _______ ____ ________ __________ ___ _______ ___ _________.
______ ________ ____ __________ __________ __________ _____ ____ ________ ______ ____.
____ _________ _______ _________ ________ ________ ________ __________ _______ _________ _____.
____ ____ ________ ___ ___ ____ ____ _________ _____ ____ ________ _______.
____ ____ __________ ________ ___ _________ ______ ____ _________.
______ _______ _____ _______ __________ ________ _____ _______ ___ _________ _____.
______ ________ ___ _________ ____ ______ ____ ____.
________ ______ ________ __________ ______ ______.
____ _______ ____ ________ ______ ___ __________ ________ ___.
_______ _______ __________ _____ _______ _______.
___ _______ _______ __________ __________ ____ ________ ________ ____ __________ ____ ___.
____ ______ ____ __________ ___ _________ _________ __________ _______ ________ ___ __________.
________ ______ __________ ________ ______ _________ ____.
________ __________ _______ _____ ___ _____ ____ _________ ___ _______.
________ _________ ________ _____ ________ _____ _____.
_____ ____ ____ __________ ________ ________ ___ ________.
________ _______ _______ ____ _______ ___ ________ _____ _________ _____.
______ _________ __________ ________.
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 MCS 11 2010 - Explain pointer arithmetic with example. Also explain advantages of ma | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→