Will dereferencing an r-value reference do anything?

Advertisements So let’s say I have this code: std::unique_ptr<int> ptr = std::make_unique<int>(10); int val = *std::move(ptr); // Anything using ptr after I know that std::move gives us an r-value reference to the unique_ptr, and I don’t think dereference will steal the resources from ptr like a move assignment operator would, so would this code be… Read More Will dereferencing an r-value reference do anything?

Unexpected Pointer Behavior in C++: Why does variable point to a local variable's value when another pointer assignment is commented out?

Advertisements I wrote this code: #include <iostream> int main() { int x = 0; int *u, *k; { int y = 9; u = &y; } int z = 11; k = &z; std::cout << "u = " << u << std::endl; std::cout << "k = " << k << std::endl; std::cout << "*u =… Read More Unexpected Pointer Behavior in C++: Why does variable point to a local variable's value when another pointer assignment is commented out?

In C, for char *s = "Hi",the output of "printf("%s",s);" is "Hi", why for int a = 1, int *p=&a, the output of "printf("%i", p)" is not 1?

Advertisements char *s = "Hi"; printf("%s",s); s here is a pointer, I set the datatype to "%s", the output is "Hi", the string. int a = 1; int *p = &a; printf("%i", p); p here is also a pointer, I set the datatype to "%i", why the output is not "1", the integer? In the… Read More In C, for char *s = "Hi",the output of "printf("%s",s);" is "Hi", why for int a = 1, int *p=&a, the output of "printf("%i", p)" is not 1?

Array of pointers initialized with array of compound literals

Advertisements I am currently reading the book "Understanding an Using C pointers" and I stumbled on the following example: int (*(arr1[])) = {(int[]){0,1,2}, (int[]) {3,4,5}, (int[]){6,7,8}} The author then shows a memory layout for arr1[0][0]…arr1[2][2] and it can be seen that the elements are stored in a contiguous region. I have two questions regarding this… Read More Array of pointers initialized with array of compound literals