Questions tagged [pointers]

Data types for "pointing" at other values: A pointer's value is a memory address where the pointed-to value is stored. This tag should be used for questions involving the use of pointers, not references. Common programming languages using pointers are C, C++, Go, and assembly and intermediate-representation languages; use a specific language tag. Other helpful tags should describe what is being pointed-to (e.g. a function, a struct etc.)

A pointer is a data type that "points to" another value stored in memory using its address. Using a pointer rather than the pointed-to entity often holds performance benefits in repetitive operations. For example, copying a pointer is very often "cheaper" than copying the value that it points to: The pointee may be a large data structure, or its copying may be non-trivial, involving memory-location dependent values, while with a pointer - only the address must be copied.

Pointers are an important concept in many high-level programming languages, including C and C++. The Wikipedia page on pointers has a fairly in-depth introduction to the concept.

Please consult some of the following content for a more in-depth explanation of pointers.

Books

See also

56155 questions
12
votes
8 answers

How to convert a char* pointer into a C++ string?

I have a C++ string. I need to pass this string to a function accepting a char* parameter (for example - strchr()). a) How do I get that pointer? b) Is there some function equivalent to strschr() that works for C++ strings?
Moeb
  • 10,527
  • 31
  • 84
  • 110
12
votes
5 answers

write data to register

i have the memory address of certain register(the address LCDCW1 is C000). c codes: #define LCDCW1 0xC000 *LCDCW1=0x31; i just want to write data to this register. The codes have problems, how to correct it? thx!
martin
  • 643
  • 1
  • 10
  • 19
12
votes
1 answer

Ampersand prepended at end of array var_dump

I wrote a piece of tutorial code and ran into something quite strange after running it. My Chrome extension Var Dumpling didn't see the last entry in the array because an ampersand had been appended to the type of the value. I tested with this piece…
Pepijn
  • 1,204
  • 1
  • 11
  • 25
12
votes
3 answers

C++: find in set of pointers

My problem is illustrated by following example: #include class A {}; int main() { A a; A * p = &a; const A * cp = &a; std::set s; s.insert(p); s.find(cp); } Compilation ends in: a.cpp: In function ‘int…
Dekakaruk
  • 661
  • 1
  • 8
  • 13
12
votes
1 answer

Simple CUDA Test always fails with "an illegal memory access was encountered" error

If I run this program I get "an illegal memory access was encountered in matrixMulti.cu at line 48" error. I searched and tried a lot. So I hope somebody can help me. Line 48 : HANDLE_ERROR ( cudaMemcpy(array, devarray, NNsizeof(int),…
Henrik
  • 521
  • 3
  • 7
  • 16
12
votes
3 answers

How to find the current line position of file pointer in C?

How can I get the current line position of the file pointer?
En_t8
  • 7,595
  • 5
  • 20
  • 14
12
votes
10 answers

Isn't this legacy code which returns a local char array wrong?

I came across some legacy code that contains a function like this: LPCTSTR returnString() { char buffer[50000]; LPCTSTR t; /*Some code here that copies some string into buffer*/ t = buffer; return t; } Now, I strongly suspect…
Emil D
  • 1,864
  • 4
  • 23
  • 40
12
votes
3 answers

Is it possible to have a pointer literal?

In C one can have string literals in the form of char *string = "string here"; integer literals: uint8_t num = 5; long literals: long long bigNum = 90322L; floating point literals: float decimal = 6.3f; Is the a way to have a pointer literal?…
secretformula
  • 6,414
  • 3
  • 33
  • 56
12
votes
3 answers

Do pointers to pointers to structs have implied interchangeability?

According to both C99 §6.2.5p27 and C11 §6.2.5p28: All pointers to structure types shall have the same representation and alignment requirements to each other. With a footnote (#39 and #48 respectively): The same representation and alignment…
Dror K.
  • 1,989
  • 17
  • 26
12
votes
3 answers

Does std::move invalidate pointers?

Assume the following: template class Pipeline { [...] void connect(OutputSide first, InputSide second) { Queue queue; first.setOutputQueue(&queue); second.setInputQueue(&queue); …
Jan Stephan
  • 403
  • 3
  • 11
12
votes
4 answers

Is C# Endian sensitive?

Is C# ever Endian sensitive, for example, will code such as this: int a = 1234567; short b = *(short*)&i; always assign the same value to b. If so, what value will it be? If not, what good ways are there to deal with endianness if code with…
Martin
  • 12,469
  • 13
  • 64
  • 128
12
votes
3 answers

How can I describe a pointer to class in a UML class diagram?

If I have a class A which contains a pointer to a class B and a method which takes in input a pointer to class B class A { private: B* attribute; public: void method(B* par); } how can I describe it in a UML class diagram? Do I have to use…
Maghio
  • 355
  • 1
  • 6
  • 18
12
votes
4 answers

Common Uses For Pointers?

I'm a programming student with two classes in C#, but I'm just taking my first class in C++, and thus I'm being exposed to pointers. I know how they work, and the proper way to use them, but I wondered about some of the ways that professional…
Alex
  • 64,178
  • 48
  • 151
  • 180
12
votes
4 answers

Pointer operator -> for golang

It seems golang does not have the pointer operator -> as C and C++ have. Now let's say I have a function looks something like this: myfun(myparam *MyType), inside the function, if I want to access the member variables of MyType, I have to do…
user1663023
12
votes
2 answers

C++ references and pointers at the compiler level

I'm trying to learn how C++ compilers handle references and pointers, in preparation for a compiler class that I'm taking next semester. I'm specifically interested in how compilers handle references in C++. The standard specifies that a reference…
Karl Giesing
  • 1,654
  • 3
  • 16
  • 24
1 2 3
99
100