What is pointer arithmetic, C/C++ Programming

Assignment Help:

Pointer Arithmetic

We can manipulate the pointers too. We can perform operations such as addition, subtraction, increment and decrement etc.,. As the pointer variables have address, adding or subtracting a number results in another address, which is at an offset from the original address. This may be memory address occupied by another variable.

e.g.

                int   i, j, k ;

                int  *iptr = &i;

                *iptr = *iptr + 2;  // I = I + 2;

                 iptr = iptr + 2 // adds 2 to address.

These are useful when using arrays.

e.g.

arr[10];

int *iptrb = &arr[0];

int *iptre = &arr[10];

While ( iptrb != iptre)

     {        

 Do something with the value if (*iptrb);

++iptrb;

}

 


Related Discussions:- What is pointer arithmetic

Loop statement, write a c++ program to accept 3 numbers and find the larges...

write a c++ program to accept 3 numbers and find the largest of 3 numbers

Described local class? why can it be useful?, It is a class defined in the ...

It is a class defined in the scope of a function _ any function, whether a member functions or a free function. For instance: // Example : Local class // int f() { c

Explain the for loop - computer programming, Explain the For Loop - Compute...

Explain the For Loop - Computer Programming? Similar to the while statement, for loop is an entry controlled loop and the code of the for loop will be executed itereatively. Th

Write a program using a friend function, Using a Friend Using a friend ...

Using a Friend Using a friend function is quite easy. The following example explains a friend function to access members of two classes. class Bclass;

Stack push pop, 2 flowcharts, pseudocode for each (at least 4 algorithms), ...

2 flowcharts, pseudocode for each (at least 4 algorithms), and code for either a stack or a queuestion..

Program to store family members details, Program to store family members de...

Program to store family members details in C++: #include #include #include struct record {   char name[30];   int age;   char state[40]; }x; //cal

Need to fix a code written in c++, Need to Fix a code written in c++,SDL2.0...

Need to Fix a code written in c++,SDL2.00 for high CPU and memory leak There is a 2D simple game written with SDL2.00 using c++. The game isn't complete and the code is a little

Lcm, lcm program.

lcm program.

Explain zero based addressing, Explain zero based addressing. - Array s...

Explain zero based addressing. - Array subscripts always start at zero. - These subscript values are used to identify elements in the array. - As subscripts start at 0, a

Area under curve, find the area of a curve y=f(x) between x=a and x=b integ...

find the area of a curve y=f(x) between x=a and x=b integrate f(x) between limits a and b   #include float start_point, /* GLOBAL VARIABLES */

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd