| | |
Pointers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 2
Reputation:
Solved Threads: 0
Could any one justify why is the result of the following code 100 100 100 99 99??main()
{
static int arr[]={97,98,99,100,101,102,103,104};
int *ptr=arr+1;
print(++ptr, ptr--, ptr ,ptr++ ,++ptr);
}
print( int *a, int *b, int *c, int *d, int *e)
{
cout<<*a<<" "<<*b<<" "<<*c<<" "<<*d<<" "<<*e<<endl;
}
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
it isnt. its undefined behaviour. your compiler could say that its anything. You modify a variable more than once in a given expression without a sequence point hence undefined behaviour.
The results of that program is unpredictable, undefined, and compiler implementation dependent. So one compiler may give one result while another compiler may give other results. why? because the compiler may, or may not, push the results of the pointer operations onto the stack after each operation. Its entire possible and conceivable that only the final result of ptr will get pushed onto the stack before print function is called.
![]() |
Similar Threads
- Pointers (archived tutorial) (C++)
- Problem About Pointers (C++)
- New to C++ Pointers and need help with identifying where the errors are (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why can't I use Pointers to point to a Enumurated Constant (C++)
Other Threads in the C++ Forum
- Previous Thread: Whats wrong with this class???
- Next Thread: code seems to stop executing
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






