logo
down
shadow

I don't understand C++ pointer arithmetic


I don't understand C++ pointer arithmetic

Content Index :

I don't understand C++ pointer arithmetic
Tag : cpp , By : Jµ.
Date : November 23 2020, 01:01 AM

will be helpful for those in need The output is not strange, it is to be expected: You have three variables in main(), all of which are stored on the stack, and which happen to be right one after the other. One of these variables is the pointer itself. So, when you dereference the pointer in the third line, you get the current value of the pointer itself.
Nevertheless, this output is not predictable, it is undefined behavior: You are only allowed to use pointer arithmetic to access data within a single memory object, and in your case, the memory object is just a single int. Consequently, accessing *pa after the first pa++ is illegal, and the program is allowed to do anything from that point on.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Arithmetic on a pointer to void (looks like easy to solve but i did not understand how to do this)


Tag : iphone , By : yossi
Date : March 29 2020, 07:55 AM
I wish did fix the issue. How recent is your copy of ASIHttpRequest? My version looks different - there is some typecasting around that pointer arithmetic. Also, which version of XCode are you using?

Attempting to understand pointer arithmetic


Tag : c , By : vferman
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You are incrementing the values before casting them to the wanted pointer
To interpret 'c' as another pointer you should rather do
printf("PTR    (c+1)  %p \n ",(unsigned int*)c+1);
item = (char*)heap + offset;
item = ((char *)heap) + offset

I really dont understand why im getting the error when creating template class shared pointer


Tag : cpp , By : Enrique Anaya
Date : March 29 2020, 07:55 AM
help you fix your problem I dont understand the error message that im getting and i have no idea how to fix that; , Your problem is in the copy constructor function:
shared_pointer( shared_pointer& a)
{
    a.pointer = this->pointer;
    howManyObjects++;
}
shared_pointer(const shared_pointer& a)
{
    a.pointer = this->pointer; // Compilation error: assignment of member ‘shared_pointer<int>::pointer’ in read-only object
    howManyObjects++;
}
shared_pointer(const shared_pointer& a)
{
    this->pointer = a.pointer; // Pay attention that this get the value of a, and not the opposite.
    howManyObjects++;
}

Having trouble extending class (Dont understand whats wrong and dont understand other complex explanations on this site.


Tag : java , By : user179190
Date : March 29 2020, 07:55 AM

I dont understand how an arrays name is a pointer to the array


Tag : cpp , By : user176445
Date : March 29 2020, 07:55 AM
This might help you Im reading a book in c++ and I was doing some tests as I didnt understand something and when I tried printing these 3 lines I was expecting something different for all 3. The first one, the location in memory of the pointer, the second one, the address stored by the pointer, and the third one, the value at the address stored by the pointer. But instead the first two were the same: ,
I dont understand how an arrays name is a pointer to the array
arey          An array
&arey         Address of the array
f(&arey)      Passing the address of the array
f(arey)       Still passing the address of the array (ish) - thanks a lot, C!
f(*arey)      Passing the first element's value
Related Posts Related QUESTIONS :
  • Use super class's address/pointer in initialization list
  • double fork using vfork
  • Convert char pointer (char*) to struct
  • Does anyone have good tips for using pc-lint?
  • C++ How fast is passing around objects?
  • template type's ctor arguments at instantiation time
  • Get list of windows in taskbar on Windows 7?
  • Curl connection options
  • Best cross-platform solution for network server?
  • simple c++ file opening issue
  • Switching from C++ (with a lot of STL use) to C for interpreter building
  • How can I access the JPEG image pixels as a 3D array like we do in MATLAB?
  • What wording in the C++ standard allows static_cast<non-void-type*>(malloc(N)); to work?
  • Avoid allocating in constructor or preserve simplicity (and RAII?)
  • Can C++ raise an error when std array initialization is too small?
  • Reference to end is ambiguous
  • Problem with basic usage of std::enable_if
  • How to print out a decimal number as octal number using setiosflags in C++
  • Open Visual Studio with solution and specific file and line
  • Enum value based on template type
  • Is there any way to swap nodes in std::list?
  • How to copy QString into wchar_t buffer
  • Make the compiler generate an empty default function for an std::function
  • Insert or push_back to end of a std::vector?
  • Best practice for const temporary types
  • Include CSV File in Complied Binary
  • Issue with binding non static function to callback
  • How can read from some files and write content of them with different form into files with same names
  • Why does auto deduce this variable as double and not float?
  • no instance of overloaded function "std::make_unique" matches the argument list, but works with unique_ptr con
  • How to see array size from a pointer in c++
  • Error taking address of temporary in Eclipse
  • Using an iterator to go through a vector and modify the contents
  • Are extern extern "C", and extern "C" extern, allowed?
  • Can't solve C2660 and C2065 Errors
  • C referencing C++ extern
  • How to write the definition of a derived class in c++?
  • Why when I include <cmath> I need to use the namespace std too?
  • How to assign a 32-bit unsigned integer to a bit field containing 32 bits
  • Why does the same class being defined in multiple .cpp files not cause a linker multiple definition error?
  • C++ 11db error when trying to quit the program in xcode. beginner level
  • Add content of a vector into a Capnproto map object
  • Recursively Pass Template Template To a Template Template Function
  • Swap rows in a 2D array with std::swap. How does it work?
  • Is there any situation in which an object's storage might change during its lifetime?
  • clang++ always generates empty profraw coverage reports
  • Do memory leaks persist after program completion if the OS does not clear it?
  • How to link library using cmake
  • How to use getters and setters without generating a copy?
  • Generating multiple amounts of the same sprite broken
  • function in c++ why my compiler didn't recognize the error()
  • Relationship between copy(...) and copy(seq, ...)
  • Are <cmath> functions required to be `noexcept` in C++17?
  • How to find a struct list item
  • How can you handle DLL versions when referencing C++ DLL's over COM from VBScript with CreateObject?
  • Do not understand how c++ set works
  • Actual build date in C++
  • How to link to already compiled external shared libraries in RCPP using Makevars?
  • combination of enable_if + std::less + sizeof... makes MSVC fail
  • Can you call the destructor without calling the constructor?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com