in Technology by
How does pointer arithmetic work?

1 Answer

0 votes
by

When we increment or decrement the pointer then pointer point to the next or previous memory location. Generally, people make mistakes, when they calculate the next pointing address of the pointer.

Here is the technique to calculate the next pointing address of a pointer when applying arithmetic operation on it. To understand this technique let us consider ptr is a pointer has data type “T” and “i” is the pointer offset.

addr( ptr + i ) = addr( ptr ) + ( sizeof( T ) * i );
addr( ptr - i ) = addr( ptr ) - ( sizeof( T ) * i );

Related questions

0 votes
    How is Pointer Arithmetic work on Character Pointer?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    How is Pointer Arithmetic works on Float Pointer?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    1.In a CPU. does the complex arithmetic and logical calculations on data. 2. The disk drive is a collection of ... of the digital dama Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    B. Fill in the blanks. 1. In a CPU, does the complex arithmetic and logical calculations on data. 2. ... thin circular discs called Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
0 votes
    What does it mean when a pointer is used in an if statement?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    Hi, I am a relatively new programmer and my teacher gave us this problem to fix. Thing is, I have no idea ... wrong with this problem? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    Can we perform arithmetic operation on pointers?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    _________ package provides basic functionalities in R environment like arithmetic calculations, input/output. (a) R ... R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Relational operators are also called as arithmetic operators. True or false no spam messages Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    Relational operators are also called as arithmetic operators. True or false no spam messages Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    What are Arithmetic, Relational &Conditional operators? Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    write a program to evaluate the arithmetic statement. X=A-B+C*(D*E-F)/G+H*K a) Using a general ... zero -address operation instruction. Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    what is the role of following components of a computer system (1) control unit (2) arithmetic logic unit ( ... (5) motherboard Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
...