A pointer is a data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

learn more… | top users | synonyms

-2
votes
0answers
39 views

swapping address values of pointers [migrated]

Below is code and I want to ask, why I am not getting swapped number as a result, because instead of swapping numbers I tried to swap their addresses. int *swap(int *ptr1,int *ptr2){ int ...
-4
votes
2answers
45 views

Converting (constant) to (address of function) [on hold]

My problem is that how to convert constant to address of function. Here an example. This code just printing that address of function. Suppose the TestFunc's address is 0x12345678 and I want to assign ...
0
votes
0answers
45 views

Checking for null pointers or allowing a math library to segfault?

I've been going through the GNU GSL design document and came across this interesting line in the Test suites section: N.B. Don't bother to test for null pointers -- it's sufficient for the library ...
3
votes
3answers
306 views

Possible alternatives to copy constructors

In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much ...
5
votes
0answers
118 views

Key / Value store development porting to modern C++

I am developing a database server similar to Cassandra. Development were started in C, but things became very complicated without classes. Currently I ported everything in C++11, but I am still ...
5
votes
3answers
1k views

Is it a common practice among professional programmers to avoid the use of raw pointers? [duplicate]

C++ tools and libraries have become more powerful than ever. For instance, we can replace arrays by vectors. We can replace pointers by references. We can use smart-pointers. Is it a common practice ...
1
vote
1answer
90 views

What does using pointer in Linux kernel imply?

So far I was under the perspective that while working in the kernel code, working with memory implies working with long integers and not pointers because dereferencing pointers shouldn't be done in ...
2
votes
1answer
151 views

What is the motivation for casting a pointer into a integer?

I'm doing some changes in the Linux kernel code and have noticed a pointer being cast into integer. Check out buf below (full code): snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream ...
2
votes
2answers
160 views

Why dynamic memory allocation functions in C returns void*?

Consider the prototypes of C's dynamic allocation functions malloc - void* malloc(size_t size); calloc - void* calloc(size_t n,size); realloc - void* realloc(void* ptr,size_t newsize); Now a ...
1
vote
2answers
155 views

shared or raw pointer c++

I am developing a noSQL database and currently moving the code from C to C++. It have class Pair, which contains a raw pointer to a memory blob. class Pair { Blob* blob; ... }; Then if you add ...
26
votes
10answers
6k views

What is the “type” of data that pointers hold in the C language?

I know that pointers hold addresses. I know that pointers' types are "generally" known based on the "type" of data they point to. But, pointers are still variables and the addresses they hold must ...
1
vote
0answers
334 views

Why C doesn't have better notation for pointers? [duplicate]

The * symbol is used for three different purposes multiplication Pointer declaration Pointer dereferencing. Why designers of C kept this notation? In other words, wouldn't it be nice if there ...
1
vote
2answers
127 views

“Sweep” a vector of pointers

I'm using a vector to store pointers to objects. In some cases I destroy one or more of these objects (setting the vector spaces to NULL after each delete call), which are externally selected: for ...
0
votes
2answers
117 views

Idiomatic C API with regards to pointers

I am trying to get a better understanding of how one would structure an API in C. I create a struct Person I have a init function that sets data on that struct I have multiple "helper" functions ...
3
votes
1answer
1k views

raw, weak_ptr, unique_ptr, shared_ptr etc… how to choose them wisely

There is a lot of pointers in C++ but to be honest in 5 years or so in c++ programmation (specifically with the Qt Framework) I only use the old raw pointer : SomeKindOfObject *someKindOfObject = ...
4
votes
1answer
170 views

The right way to remove an item from a linked list

In this Slashdot interview Linus Torvalds is quoted as saying: I've seen too many people who delete a singly-linked list entry by keeping track of the "prev" entry, and then to delete the entry, ...
1
vote
2answers
544 views

Disadvantages of Pointers [closed]

I was wondering why pointers are not included in modern languages now-a-days. I already did research on this on internet, and found out few theories/reasons: Memory leakage is the biggest concern ...
7
votes
2answers
256 views

Autoreleasing objects in Reference Counting Systems

I'm experimenting a bit in C and I'm trying to implement my own Reference Counting System. I've mainly worked with Objective-C in the past but AFAIK autoreleasing objects is something that is unique ...
0
votes
2answers
330 views

C Linked List Implementation Pointer vs. Pointer-to-Pointer Consistency

To get some practice in C, I'm writing some basic functions for operating on a linked list of ints. I started out with functions that accepted as a "list" a pointer to the head node. Now, I find ...
0
votes
3answers
751 views

C++ Chess board design and smart pointers [closed]

I wrote a Chess engine in Java and I am porting it over to C++. I am new to C++. The idea: I have a Board object which holds a 2-dimensionnal array of Piece objects. Queen, Rook, Bishop, etc are ...
1
vote
4answers
481 views

How to work around Java's lack of pointers to pointers when working with linked data structures? [closed]

I've learned from a textbook how to implement binary search trees recursively in Java, and am working on implementing them nonrecursively. I've found a simple and elegant way to implement an insert ...
3
votes
5answers
858 views

Storing a pointer to an argument passed by (non-const) reference

When designing an interface for passing objects which are meant to be stored for later use and which should not be 'null', I am always a bit uncertain if the argument should be passed by reference or ...
2
votes
6answers
777 views

What are memory addresses? [closed]

I have more or less 0 knowledge in low-level topics, so forgive my possible ignorance. I know that in languages such as C, pointers hold 'memory addresses', i.e. strings (or binary data?) written in ...
21
votes
12answers
6k views

Why does void in C mean not void?

In strongly-typed languages like Java and C#, void (or Void) as a return type for a method seem to mean: This method doesn't return anything. Nothing. No return. You will not receive anything from ...
0
votes
1answer
112 views

In C++11 can Auto be used to get around mis-casting of void * parameters in functions?

If I have a generic function that takes a void* as a parameter, can Auto in C++11 help stop any bad casting of that parameter? For instance, we may have an event system that sends events and a ...
20
votes
3answers
5k views

Why Increment Pointers?

I just recently started learning C++, and as most people (according to what I have been reading) I'm struggling with pointers. Not in the traditional sense, I understand what they are, and why they ...
-2
votes
2answers
2k views

Assigning strings to pointer in C Language

I am a new learner of C language, my question is about pointers. As far i learned and searched pointers can only store addresses of other variables, but cannot store the actual values(like integers or ...
11
votes
4answers
1k views

Pointer indexing

I am currently reading a book titled "Numerical Recipes in C". In this book, the author details how certain algorithms inherently work better if we had indices starting with 1 (I don't entirely follow ...
1
vote
2answers
397 views

Can a version of Python's shelve module that knows when its entries have been modified be written in any programming language?

shelve is a Python module that makes it easy to persist a Python dictionary to disk (under the right conditions). The documentation for shelve gives this example to demonstrate one of the pitfalls of ...
0
votes
3answers
3k views

usage of double pointers and n pointers?

I am familiar with basic C pointers. Just wanted to ask what is the actual use of double pointers or for that matter n pointer? #include<stdio.h> int main() { int n = 10 , *ptr , **ptr_ptr ; ...
0
votes
2answers
277 views

Usage of raw pointers

So from the top-voted answer to this question, it appears that using raw pointers for storage isn't frowned upon so much. However, then what is the point of a std::weak_ptr? I thought that storage was ...
0
votes
5answers
210 views

What conclusion to be drawn from no difference in generated assembly from 2 rather different programs?

I might not have had a counterexample when I got the reply "A pointer is just an address, what's the difficulty?" but I didn't really buy such a simple explanation and at assembly code it's not ...
-1
votes
2answers
210 views

Difference between a pointer and a reference? [duplicate]

In Java and other high-level languages, a reference leads to an object. In C++, as far as I know, a pointer can also lead to an object. So what's the difference between a reference leading to an ...
0
votes
3answers
290 views

ANSI C pointers corrupted values

I am working on ANSI C and having some issues with the pointers. That is that after a point in my program the pointer's values change without me interfering, is something like overwriting them. I ...
2
votes
3answers
393 views

Why are pointers to literals not possible?

Reference to a literal is possible only if the reference is declared as constant. But why is a pointer to a const object not possible in case of literals? i.e. int const& ref = 5;// But why ...
24
votes
4answers
4k views

Why do C++ and Java both use the notion of “reference” but not in the same sense?

In C++ a reference argument to a function allows the function to make the reference refer to something else: int replacement = 23; void changeNumberReference(int& reference) { reference = ...
1
vote
3answers
477 views

How do you read this line of code?

Forgive me for my poor English, me and my friend were doing school homework, suddenly he asked me to read this line of code ptr = &array[1][1][1] (ptr is a pointer to an integer). He said ...
4
votes
2answers
411 views

Is it better to use an external variable or to pass around a pointer?

While writing in C, I have always wondered about when is the best time to use an external variable. I generally prefer to pass a pointer into a method. Is there a correct time to use an external ...
4
votes
3answers
246 views

adding array pointer in c

I am having problems understanding how this equation works in c: char *sum(char *a, int b) { return &a[b]; } printf("%d", sum(5, 4)); I understand how arrays work, and I understand how to ...
3
votes
2answers
2k views

Storing a pass-by-reference parameter as a pointer - Bad practice?

I recently came across the following pattern in an API I've been forced to use: class SomeObject { public: // Constructor. SomeObject(bool copy = false); // Set a value. void ...
3
votes
1answer
688 views

What are the real life use cases for tagged pointers? [closed]

What are the real life use cases for tagged pointers? This is mostly coming from reading about small 64-bit systems and possible uses of 64-bit word pointers. To my understanding tagged pointers are ...
1
vote
1answer
603 views

Pointer access and cache coherency

To my understanding, when you access a variable, that variable and the surrounding area of memory is put into the L1 cache. If I'm wrong here, please tell me. Now my question is, say I have an array ...
3
votes
5answers
959 views

What is the definition of pointer? [duplicate]

Conceptually a "pointer" is just something that "points" to something else;Is this definition is sufficient to tell exactly what a pointer is in programing languages? Does it need to have any other ...
2
votes
2answers
8k views

Do pointers really exist in Java? [duplicate]

I read quite a few resources on the internet and now I am quite confused about the existence of pointers in Java. Some claim that there are pointers and some claim that there is no such concept. So ...
1
vote
3answers
301 views

Garbage collectors and pointers/ reference

I am a little confused on both pointers and reference. From my understanding pointers are addresses in memory. If I pass a variable using pointers and reference to a function, any manipulations of ...
0
votes
1answer
516 views

Is there a proper way to allow access to private list by reference?

I'm trying to provide a by-reference getter to a list of objects in a class. My setup looks something roughly like this: class c_Container { public: c_Item* Get(int uid); private: c_Item ...
6
votes
1answer
241 views

Hardware that accelerates pointer dereferencing?

Most modern languages make a heavy use of pointers / references: a typical OOP language uses VMT lookups, a typical functional language builds key data structures out of pointers, etc. Even typical C ...
7
votes
1answer
3k views

Is this a valid example of a dangling pointer?

The book "Data Structures in C" (Horowitz and Sahni) suggests that in the following code the pointer pf is behaving as a dangling reference: float f,*pf; pf=(float*) malloc(sizeof(float)); *pf=2.6; ...
4
votes
4answers
2k views

Was C designed to facilitate Object-Oriented programming?

I am trying to broaden my understanding of the history and development of object-oriented programming, and I am curious to find out if C was designed to facilitate Object-Oriented programming? (like ...
6
votes
5answers
11k views

Is there any difference between pointers and references? [duplicate]

References and pointers do the same thing as I know. Is there any difference between them? If there is no difference, why we call them reference not pointer?