Questions tagged [dereference]

Anything related to pointer dereference, i.e. the process of determining the object which the pointer is referring to. Languages having pointer variables usually have a special operator to perform dereferencing of pointers (e.g. in C and C++, if `p` is a valid pointer, `*p` is the object pointed to by `p`).

Anything related to pointer dereference, i.e. the process of determining the object which the pointer is referring to. Languages having pointer variables usually have a special operator to perform dereferencing of pointers (e.g. in C and C++, if p is a valid pointer, *p is the object pointed to by p).

1184 questions
-2
votes
1 answer

I add values into a C array in one function, array is still empty in later function, what gives?

The pointer is declared int *v; And the two functions are called. createMemObjects(M, N, v, context); transferToDevice(M, v, commands); So in my first function which I pass int *pv into, I fill the array: pv = malloc(sizeof(int) * M); memset(pv,…
Chucky
  • 1,701
  • 7
  • 28
  • 62
-2
votes
3 answers

pointers & references in c++, when and where

I am coming back to C++ after a long venture in Java world, and am regrasping the concept/syntax of how C++ uses pointers. So a couple of examples. in java public void MyFunc(MyClass class) { class.DoSomething; } is the same as…
WIllJBD
  • 6,144
  • 3
  • 34
  • 44
-2
votes
1 answer

C++ postfix incrementation during list push_back

I have a code flush[*it % 4].push_back(*(it++) /= 4); and it was meant to push_back the new value(old value/4) before incrementing the it iterator, is it right like this or how to do it the fastest way to get value from iterator, divide it by 4,…
Lukas Salich
  • 959
  • 2
  • 12
  • 30
-3
votes
2 answers

Confusion about C pointers

I am sending this message to clear my confusion that I could not manage and handle. The foo1 function code should work. I am giving the code details for you. When I run the code, the result is a segmentation error at line 12. Then I made a little…
synapsis
  • 15
  • 2
-3
votes
1 answer

type &var = *ptr VS type var = *ptr

Let foo be: class Foo { public: Foo(int a) { aa = a; cout << "foo built. " << aa << endl; } ~Foo() { cout << "foo DIED. " << aa << endl; } int aa; }; Also, assume we have: Foo* func1(){ Foo* foo =…
salehjg
  • 49
  • 1
  • 9
-3
votes
1 answer

C Pointer Logic

I have a pointer to a struct that contains a pointer to a short value. The following is the struct. typedef struct { short *val; } x; If I have a pointer to a variable of type x, I can dereference it and access an element of the struct by doing…
Ralph
  • 37
  • 6
-3
votes
1 answer

What is pointer Derefrencing in C?

I was learning about recursion using c and there was a question with an array say for example: void main(){ char str[100]; --snip-- if(*str == 'c') count++; --snip-- } here *str is the value retrieved from the pointer…
-3
votes
2 answers

Accessing element from reference to vector of pointers

I have a reference to a vector of pointers, as follows: std::vector& objects; How can I access Objects from this vector?
Con O'Leary
  • 99
  • 1
  • 10
-3
votes
1 answer

Accessing objects in a map pointer in golang, does the dereferencing causes a copy of the map?

In my code I create a map pointer which I then dereference to retrieve an item. a := "...big JSON string..." b := map[string]B{} json.Unmarshal(a, &b) c.my_map = &b ... // and my fetch function does: result = (*c.my_map)[id] When dereferencing…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
-3
votes
1 answer

What is the memory address and pointer address in the following image?

I was just playing with pointer. And I understood only line 5, 6 and 10, 11 completely. What I want to know is which one is the address of pointer here? And what does line 7 and 14 implies? Additionally what is the meaning of %p, using this code as…
-3
votes
1 answer

Assigning pointer values

I'm a beginner to C language and don't understand presumably easy concepts of the pointer, string, etc. The source code is as follows. #include int main(void){ char *p="Internship "; printf("%s\n", p); printf("%c\n", *p++); printf("%c\n",…
user13483869
-3
votes
1 answer

What is the difference between int *[5] and int (*)[5] in C?

I am trying to understand the difference between int *[5] and int (*)[5] and my simple code is as below. int main() { int a[5] = {10,11,12,13,14}; int *ptr[5]; ptr = &a; } What is the difference between int *[5] and int (*)[5] in C?
Guruprasad
  • 11
  • 3
-3
votes
1 answer

iterator acting weird while in for_each

Doesn't an iterator have to be deferenced before using? I can't understand why for_each(vecResult.begin(), vecResult.end(), [](auto counter) {cout << counter << endl; }); is working (showing the contents of the vector)…
John
  • 1
-3
votes
2 answers

Dereferencing head of empty linked list for next node

I was trying to implement linked list in C++, when this idea struck my mind. With standard node definition as class node { public: int data; node *next; }; I created an empty list node *head; then tried this if(head->next == nullptr) …
Snigdh
  • 61
  • 11
-3
votes
1 answer

I am at a loss for why this is code is giving me a read acess violation. dereferencing pointer and subtracting another char should work in Theory

I dunno why this doesn't work. the code has a problem with the *c in charToInt function but should be a legal statement in c. at least so I thought. I am excited to learn something new here. int charToint(char *c) { return *c - '0'; } int…
teaNcode
  • 19
  • 1
  • 7