# Questions tagged [pointers]

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

351 questions
Filter by
Sorted by
Tagged with
421 views

### Simple string manipulation in C (for small microcontrollers)

Although I have long experience of other languages, I've not used C until playing around with microcontrollers using the Arduino IDE. I'm a bit uncomfortable with my use of pointers in conjunction ...
437 views

### C++ Garbage Collector - Simple Automatic Memory Management

I made a general smart pointer which fixes the problems of loops between std::shared_ptr's. While use is simple, I feel that my code is inefficient and clumsy. Here ...
51 views

### Testing MRU-list vs. standard list

The task is to test the the benefits of a Move-To-Front Linked List vs. a standard Linked List. It was also meant to practice inheritance and pointers. The standard functionality is in ...
2k views

### Left Shift/ Right Shift an array in C

I am trying to implement a Left shift/ Right Shift on arrays. I was able to accomplish this using double loops. Can the efficiency be improved? This is the working code for LeftShift/RightShift which ...
1k views

### FizzBuzz, but with provided start and end of sequence, results stored in array, and a separate function to convert integers to strings

To learn C, I'm doing the traditional FizzBuzz challenge with extra restrictions: The start and end of sequence is provided by the user Instead of directly printing the results, the results must be ...
125 views

### Improving my implementation of a unique_ptr - PPP Stroustrup book

This question is an improvement of this one here: Implementing a unique_ptr - PPP Stroustrup exercise Here's my new code, following the suggestions by @JDługosz. I agree with the fact that T* ...
58 views

### Implementing a unique_ptr - PPP Stroustrup exercise

I'm doing the following exercise from PPP - Bjarne Stroustrup, Chapter 19, ex.10. Implement a simple unique_ptr supporting only a constructor, destructor,...
329 views

### Hack machine language assembler as required for project 6 of Nand2Tetris

This is the implementation of the Assembler required to parse source code written in the Hack Machine Language and output it to a 16-bit binary file. After writing one go in Swift, I decided I wanted ...
1k views

### Minimum of two floating-point numbers

I'm learning C and I just had the exercise to write a function that checks for the lower one of two floating-points. So I thought, I either could use pointer and also return the pointer of the lower ...
46 views

### Linked list - append, insert, print

I am a beginner in C and am learning linked lists. I have made a program to implement a linked list, allowing certain operations on the linked list. There are 3 functions: ...
80 views

### A safe type-erased Fn Pointer in rust that can be used to call associated and regular function

I am implementing a callback method to replace the use of generics. For maximum performance, it is not allowed to use Box and I also don’t want to use ...
2k views

### Implementation of itoa which allocates the string

This is my implementation of itoa() (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The caller is not ...
46 views

### Decoupling receiving data and processing data by passing callback and shared_ptr

Sorry for my poor English. I want to decouple receiving data and processing data, this is the demo code: ...
65 views

### Possible optimization for finding small bitmap in large bitmap in C# without unsafe code?

Background I am creating a tool to locate a small bitmap in a large bitmap by comparing each pixel. Since I am by far no professional programmer, I was searching for some code snippets and found this. ...
173 views

### Storing a copy of unique_ptr

When one writes c++ code to manipulate LinkedLists, Trees, etc. one creates a tmp pointer that points to the start/root and changes that pointer as one traverses along. What would be the equivalent ...
34 views

### Inquiring possible alternatives to custom hierarchy-aware smart pointer

I have a medium sized project that uses a class hierarchy that essentially boils down to: ...
109 views

### Implementation of std::atomic<std::shared_ptr<T>> for C++20

As you may know, C++20 has added std::atomic<std::shared_ptr<T>> specialization to the standard, but sadly, most compilers have not implemented it yet. ...
949 views

### De-/Serialization of structs representing TCP messages

I wrote two template functions to serialize and deserialize structs representing messages to be sent and received via a TCP socket: ...
56 views

### Merge Sort for Linked List Criticism in C

I previously implemented a Merge Sort for arrays, so after fixing up my code for the array-based merge sort I have now implemented a merge sort for a basic singly-linked list data structure which only ...
55 views

### Scanning multiple strings in one line to a pointers array in C [closed]

I'm trying to write a code for a function that takes an empty array of pointers and its length n. And scans n strings of max length of MAX_LEN (a defined constant) until a new line is given by the ...
207 views

### C++ Simple Shared Pointer Implementaion

I wrote an implementation of a shared pointer. I would like a review of it. It seems to work, but running it through Valgrind shows that that it leaks memory somewhere in my tests, but I don't know ...
334 views

### "observer pointer" meant to stay updated when the pointed object is moved in memory

I wasn't sure about how to name it, maybe "follow_ptr", "self_updating_ptr", or "stalking_ptr" or something on those lines. For now it's called Identifier. What I'm ...
569 views

### dynamic_pointer_cast for std::unique_ptr

dynamic_pointer_cast is only implemented for std::shared_ptr, I need it for unique pointers. The wrinkle is that dynamic_casting ...
105 views

### Reference-counted smart pointer in C

About I've been experimenting with gcc's __cleanup__ attribute, and thought it'd be a great fit for a memory-safe smart pointer for C. This is the implementation. ...
232 views

### Tic-Tac-Toe game in Java

I had to write a TicTacToe game as an assignment for class & the last program I wrote used a few continues here and there. When I asked for a peer code-review I was informed that I should use ...
96 views

### C++ wrapper for font opaque pointer

I'm creating a class which has a raw pointer member which comes from a C function. In order to make it RAII approved, I just created a method free() that is called ...
645 views

### shared_ptr and make_shared implementations (for learning)

Recently, I've been going through Scott Meyer's Effective Modern C++ and found the discussion on shared_ptr really interesting. I also watched Louis Brandy's ...
261 views

### C++ shared pointer wrapper for lazy initialization

I have written a very simple wrapper around std::shared_ptr that supports lazy initialization. Do you see any problems? ...
64 views

### Generic stack implementation in C

I haven't separated the stack code into its own header and source yet, this is just a proof of concept for now. Haven't chosen better function names yet because I ultimately want to integrate this ...
53 views

### Pointers and arrays

I just started to learn pointers, so I'm interested if I used them correctly in this task where I check if the absolute value of the greatest element in an array is two times greater than the absolute ...
15 views

### Using (templated) function-scope static address as Unique ID [closed]

typedef const bool* const TypeID; template<typename> TypeID TypeIdOf() noexcept { static const bool idLoc(0); return &idLoc; } I'm using ...
501 views

### C++ Shared_Ptr implementation

I reinvented a c++ smart pointer, shared_ptr to be precise. It is meant for practice purpose and does not attempt to replace the standard implementation. To the ...
629 views

### Double Linked List with smart pointers: problems with insert method

I'm trying to implement a Templated Double Linked List, following Stroustrup's book "Principles and Practice using C++", Chapter 20.4. Instead of raw pointers, I want to use unique pointers. ...
76 views

### How to eliminate derefs?

Spoiler: Advent of Code 2020 Day 8 Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come ...
321 views

### How to use smart pointers with SDL2 (SDL_RWops)?

I want to write read savefile function with smart pointers and SDL2. I have little expirience with smart pointers and just want to ask is my code good, correct and no memory leaks. this is my code: <...
303 views

### Maintain a list of contacts in C

I have a function that gets a string and prints it as a message. Then, it reads the text from stdin, saves it in a pointer and sends it back: ...
57 views

### Use of pointers in C in Erasthenes sieve program [closed]

I made the following code in C, which is supposed to create a list of booleans $n + 1$ long, such that the $i$'th element is true if $i$ is prime and $i$'th element is false if $i$ is not prime (...
123 views

### Extreme use of pointers in adjacency list graph construction?

Playing around with pointers in C++, implemented an adjacency list graph. Am I going too far/extreme trying to place data onto the heap? graph.h ...
601 views

### Using smart pointers to construct Binary Search Tree

I have three main questions: Am I using std::unique_ptr correctly here? Using std::move and ...
591 views

...
112 views

### Switching first names with surnames

The objective is to get a list of number and then switch the last person surname with the first person surname; when I type '\$' it do the changes and finish the program! (POINTERS and DYNAMIC ...
44 views

### Using std::function to write a function that returns a function

Our C++ professor told us to practise the use of std::function, lambda and pointers to functions. He asked us to: Write the function ...
510 views

### C# class to dump the memory of a process in several formats

I made this because I couldn't find any good C# classes/libraries that allow you to dump the contents of a process' memory into a file or a byte array. I haven't tested this on 32 bit systems but it ...
155 views

### Implementing a binary search tree using std::unique_ptr

I have implemented a binary search tree with 2 operations to begin with. I have tried to implement it using the best practices I could think of. Overall, I am happy with the implementation. But, I ...
148 views

### Simple C++ Test class with rule of 5

It has been a long time I used c++. So I brushing over concepts for interview preparation. Can you please help me with code review? If you have any observations/bugs/alternatives please point out. For ...
96 views

### Add two digit strings and return the result as string

I haven't done C in a while. This looks like a simple problem to start. Leetcode problem 415 Given two non-negative integers num1 and ...
228 views

### Using unique_ptr in FreeRTOS

I am trying to implement smart pointers for our project. We're using FreeRTOS which is written with a C API so it was quite a challenge to implement sending smart pointers around but somehow I managed ...
83 views

### String input and split functions in C

I've some functions targeted to simplify working with strings in some of my other projects. I'd like feedback on this code and whether or not the implementation is efficient and memory safe. I work ...