POINTER ARITHMETIC
10 flashcards · Programming Languages · by Joelanandraj Edwardraj
What is the output of the above code ?
2 Incrementing a pointer makes it point to the next block.
After executing the below statement, what is the value ptr points to.
4
After executing the below statement, what is the value ptr points to.
3
Which direction the pointer moves if you add it with a number ?
Right
Which direction the pointer moves if you subtract it with a number ?
Left
What is the output of the above code ?
5 Decrementing a pointer makes it point to the one block behind it.
What is the output of the following code ? After execution of the code will the pointer moves ?
3 1 Adding a constant with a pointer won`t alter its address. It will just look ahead and returns the value that's it. The pointer remains in the same spot as shown below.
What is the output of the following code ?
3 4 Similarly subtracting a pointer with a constant won`t alter its address. It will just look behind and returns the value that's it. The pointer remains in the same spot as shown below.
Is 'Ihs' lesser than 'rhs' ?
True The address of each block in a memory segment is always contiguous. So, the lhs is always lesser than rhs. What we can infer here is we can technically compare two pointer.
Write a code block to display all the value from lhs to rhs.
while(lhs<rhs) { printf("%d",*lhs++); } Incrementing lhs movies the pointer through the board and eventually you are able to display its value.