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.)

pointers
Filter by
Sorted by
Tagged with
1 vote
1 answer
27 views

Zig convert std.os.argv to C type argv

I have a zig project integrating with a c library (xlib). The library has a method that requires I pass the entire argv array to it as a parameter. In the zig extern definition the expected type of ...
Alex's user avatar
  • 457
1 vote
1 answer
87 views

Arrays and sizeof() in C++ [duplicate]

It is said that when an array is passed as a parameter to a function, it decays into a pointer and the length of the array needs to be passed as a parameter as well. This implies that the original ...
Kotaka Danski's user avatar
0 votes
0 answers
23 views

Double pointers in RISC-V assembly

I'm attempting to optimize a specific part of a C function using RISC-V assembly, but I'm not sure how to properly pass double pointers through the function. The issue arises because the argument is ...
Tamara Boškov's user avatar
0 votes
1 answer
50 views

Unexpected value when dereferencing pointer in C

The following code #include <stdio.h> int main() { long long data = 0xFFFEABCD11112345; char *pData = (char *)&data; printf("Value at address %p is %x\n", pData, *...
atta's user avatar
  • 3
1 vote
2 answers
78 views

How do I overwrite a string buffer without modifying earlier uses of it

I've recently started learning C, and I'm trying to implement a hash map datastructure. I'm currently implementing my buckets as dynamically resizing array-backed lists. When testing my bucket_remove ...
Kyohei Kaneko's user avatar
-2 votes
0 answers
64 views

Why can’t I access the fields of class A through a unique_ptr to A? [duplicate]

Why can't I access the fields of class A through a unique_ptr named pA, but I can through a regular pointer named pAptr? template<typename T> class A { public: A(T data) : _data(data) {}; ...
user24351480's user avatar
0 votes
0 answers
79 views

Is it possible for a unique ptr to store a template class and access its fields? [closed]

Is it possible for a unique ptr to store a template class and access its fields? I'm facing a problem that I can't access the fields of a class that is stored in a smart pointer. but with a regular ...
user24351480's user avatar
1 vote
3 answers
58 views

strcmp with array of pointers

I am working on a function to sort a array of pointers to an array of strings. I am done building the code but it crashes without an error message. The debugger tells me that it crashes at the if(...
Peter Kirsch's user avatar
0 votes
0 answers
31 views

How to fill an array that created in the main function in a void function with Pointers?

#include <iostream> using namespace std; void add_numbers_to_array (int *array); int main() { int array1[] {}; int array2[] {}; cout << array1 << endl; cout <&...
Burak's user avatar
  • 1
0 votes
2 answers
62 views

Arrays and pointers in C using malloc

I have this code which works. But I'm confused about how pointer arrays work, don't you have to initialize the array? How is this block of code able to just have &arr[i]. Secondly, why don't we ...
Green_Crocs's user avatar
0 votes
1 answer
40 views

Pointer Arrays and Addresses

I am starting to work on the topic of pointer arrays. I have assembled a little Test-Code but i am frustrated since line 14 and 15 do not print the same value hence the address of student1[0]. The ...
Peter Kirsch's user avatar
0 votes
0 answers
43 views

Why address of the any pointer stores in their respective datatype(C) [closed]

int myAge = 43; printf("%p", &myAge); // Outputs 0x7ffe5367e044 int* ptr = &myAge; See here the address of the myAge is some hexadecimal value. Why do we store the address in ...
Yuvraj Singh's user avatar
0 votes
1 answer
55 views

Logical error in a simple banking system program in C

So, when the user deposit an amount on the account(struct), the balance does not get updated and thus I can't proceed with other operations like withdrawing etc. #include <stdio.h> #include <...
Healing_Salve's user avatar
0 votes
4 answers
91 views

What realloc() actually does in this code?

#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char *s; s = malloc(1024 * sizeof(char)); scanf("%[^\n]", s); ...
chiranjeevi_dk's user avatar
0 votes
2 answers
58 views

Why cant I modified the char array when passing it as an argument to the function and assigning it a new value?

void changeName(char* name) { //other action //strcpy(name, "String"); -- this working name = "Marcus"; // -- this not working } int main() { char name[10] ...
Tan Choon Shen's user avatar
0 votes
1 answer
37 views

part of multidimensional array not accessible after assignment to different part

I have a 3 dimentional array. int maxStrLen, int numberColumns, int numberRows are all set to like big numbers, that cannot possibly result in out of bounds for input char*** array = malloc(sizeof(...
Jeremy Khoo's user avatar
-4 votes
2 answers
112 views

Why do the two pointer arrays return different addresses?

In the following code, I thought that the two outputs were the same. But in fact they are not! In my computer, the first output is 0x6ffde0, while the latter output is 0x6ffdb0. #include<iostream&...
Mark_Phys's user avatar
  • 103
0 votes
1 answer
51 views

Expected fn pointer, found closure, when i pass struct for the function [closed]

I created an impl to be able to manage some asynchronous functions that must be executed as soon as my app opens. My problem is that when I pass a struct as a parameter, the compiler gives the ...
Marcelo Magalhães's user avatar
1 vote
1 answer
38 views

Rust Arc pointer comparison fails despite same memory address

In Rust, I'm trying to make a group of objects that can be related to one another in a sort of target/dependency chain. I figured I could use a trait and, for each object, assign a "target" ...
RodoGM's user avatar
  • 11
1 vote
0 answers
89 views

Using a pointer to a structure returned by a C++ DLL

I'm using functions of a C++ DLL from Delphi (dynamic linking with LoadLibrary). Amongst these, get_all_hook_functions_V2() can return a pointer to a structure populated with functions adresses, that ...
David Chesnet's user avatar
1 vote
1 answer
69 views

want to understand pointer to struct and void pointer conversion

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct person { char *name; unsigned int age; unsigned int height; unsigned int weight; } person_t;...
raghavendra's user avatar
0 votes
0 answers
144 views

Fortran Error: Function Result Must Have Pointer Attribute in Legacy Code [closed]

I'm maintaining a legacy Fortran project that incorporates FORTRAN 77 code developed by Ernst Hairer. I've encountered an issue during compilation that I'm struggling to resolve. error: Command "/...
Foad S. Farimani's user avatar
2 votes
3 answers
112 views

Pass reference argument to STL container element constructor

Very often in C++ I want an STL container of a type which has a reference member: struct C {}; struct S { S() = default; S(const C& c) : _c(c) {} const C& _c; // I always ...
intrigued_66's user avatar
  • 16.6k
1 vote
1 answer
58 views

How to init a Struct within a Enum in unsafe codes

I'm trying to initialize an enum variant, which is a struct in my case, using Box::new_uninit_in and ptr::addr_of_mut!. However, I'm struggling to access the right field. Can someone help me with this ...
DrunkenRandomWalker's user avatar
-2 votes
0 answers
54 views

Shared pointer reassign and delete [closed]

I'm new to c++. I used shared_ptr for an edge_contraction function void Edge::edge_contraction() { std::shared_ptr<HalfEdge> v0_he = this->he; std::shared_ptr<HalfEdge> v1_he =...
Link Lin's user avatar
1 vote
2 answers
47 views

Calling `free` syscall for the first element array of void* in C

Here's a snippet of C code: int main() { void **values = calloc(10, sizeof(void *)); int *a = malloc(sizeof(int)); *a = 100; int *b = malloc(sizeof(int)); *b = 200; values[0] ...
shayan rok rok's user avatar
-1 votes
3 answers
72 views

Object attribute reference causes SIGSEGV [duplicate]

/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#,...
KawkaGaming's user avatar
0 votes
1 answer
94 views

Unable to store a pointer to a class in C++

I am coding a model kit collection manager and for that I coded a shell that has a few variables that go like that : class MonkeyShell { private: bool _exitFlag; // Value that keeps the loop going ...
GAlbert's user avatar
0 votes
1 answer
19 views

Shuffle merging two linked lists with the same number of nodes

I have two functions for merging two linked lists assuming they have the same number of elements The first one: `def shuffle_merge(self, l1,l2): node1 = l1.head node2 = l2.head if not ...
notsoanonperson's user avatar
0 votes
1 answer
61 views

Unreal engine: Pointer points to another address one frame later

I'm having weird a behavior with the first code block below in UE5.3, Did not test on other engine versions and I apologize if it's a beginner issue! class MyClass { private: float* Value; public: ...
Rav Rayle's user avatar
0 votes
0 answers
65 views

Assign one array to another in c++ [duplicate]

#include <iostream> using namespace std; int main() { int arr[][2]={{1,2},{3,4}}; int* temp=arr[0]; arr[0]=arr[1]; arr[1]=temp; } Hey I am trying to swap between rows in 2d array, I ...
miiky123's user avatar
  • 109
-1 votes
0 answers
53 views

Longest Palindromic Substring with unknown heap-buffer-overflow error

Trying to solve leetcode problem -Longest Palindromic Substring i worked on it in my IDE and everything went well, the algorithm works as it should. after that i tried to submit it on leetcode website ...
Maamar Darmech's user avatar
0 votes
0 answers
61 views

Delayed program running of c program when i declare a pointer

Below is a program related to linked list, specifically a insertion operation. #include <stdio.h> #include <stdlib.h> typedef struct Node { int data; struct Node *next; } Node; ...
Blender Stuffs's user avatar
0 votes
0 answers
35 views

Problem with updating value in a Pointer location

The problem statement of Hackerrank Pointers question for C++ is to update two Pointers value, one with the sum and other with the difference using a function named update. The solution code is :- #...
Shogun BS's user avatar
5 votes
1 answer
106 views

Can you declare a C pointer with its own address?

Can I declare a C pointer with an intialization to its own address? void* p = &p; I am specifically concerned with if this is strictly standard compliant in C23 (as the draft currently stands). I ...
Kyle's user avatar
  • 950
0 votes
3 answers
70 views

Should I use **array or (*array)[] for a 2D integer array?

I am writing a function which requires me to pass a 2D array of integers as a parameter with a variable amount of rows but fixed number of columns. I was initially planning to use: void function(int (*...
Pahheb's user avatar
  • 1
2 votes
1 answer
88 views

How can I point a void pointer to different objects that share have different implementations of a virtual function?

I have a pointer that I'd like to point to different instances of classes that share an abstract base class, and then call a function on the pointer that each child class has its own implementation of ...
oretomos's user avatar
0 votes
0 answers
19 views

C the end values of an array that was created in a seperate function have garbage values in them [duplicate]

This is the code that I used, all the printed values were 0 except the last 3 which were garbage values. #include <stdio.h> #define ARR_LEN 5 int* arrCreate(); void printArr(int* arr, int ...
TiWl's user avatar
  • 1
1 vote
2 answers
110 views

How to write a C++ function that deletes a pointer instead of a macro

I found a macro in legacy code that deletes a pointer. I tried to replace it with a function, and it crashed the application. I can't figure out why. Is there something wrong with my function? //...
Jerome Demantke's user avatar
-1 votes
1 answer
113 views

How to deal with duplicate deletion of pointers in C++

Recently I got stuck in a scenario where I was using both raw and smart pointers simultaneously in a project. I have 2 classes. Canvas which composes another class CanvasItem. It stores CanvasItem ...
Tauseef_Ahmed's user avatar
0 votes
1 answer
61 views

Why edditing value using pointer, that is class private field, requires declaring additional variable?

I have defined three simple files: main.cpp #include <iostream> #include "EventHandler.h" int main(int argc, char *argv[]) { bool myFlag = true; EventHandler eventHandler = ...
Ave's user avatar
  • 33
1 vote
2 answers
62 views

Why does this function return a pointer instead of pointer's value in C language?

#include <stdio.h> #include <stdlib.h> typedef struct { int *array; int size; }Array; Array array_create(int init_size); int* array_at(Array *,int index); void ...
jim chen's user avatar
0 votes
1 answer
57 views

Taking an int from shared memory

In my current project, I have to work with a zone of shared memory of 100 bytes, plus an integer right after it, so, around 108, I think. However, I can't seem to isolate this int. I don't have much ...
DesdreMBM's user avatar
1 vote
1 answer
85 views

How can * both declare pointers and dereference pointers?

I'm confused as to how the dereference operator functions in pointer declarations. Consider both these scenarios: int y = 5; int *x = &y; int y = 5; int *x; x = &y; The second scenario (...
tnr's user avatar
  • 13
0 votes
0 answers
83 views

Is there anyway to modify an allocated char pointer in a function and then use that value outside of the function?

First of all, I am using visual studio (if that even means much in this context) and I am building my first win32 API application. At the beginning of my code I have char *answer = (char*)malloc(...
Thomas Wallace's user avatar
0 votes
2 answers
43 views

LLVM API produces invalid IR for ptr type

I am using LLVM 15 and I am trying to compile a language of my own (pretty much like Pascal in terms of syntax) to LLVM IR and I am using Ocaml. When I try to create a struct and set its body to have ...
lil_papa's user avatar
-1 votes
2 answers
82 views

Why does the add instruction in assembly seemingly make an implicit sizeof() conversion?

Consider the following x86 ASM instructions: mov eax, [ebp+StrPointer] add eax, 1 mov [ebp+StrPointer], eax Here, [ebp+StrPointer] is a pointer to some heap allocated string. Apparently, ...
Quinn Norton's user avatar
-4 votes
5 answers
122 views

what is *(*(*p))) pointer in C?

I need print 5 from data using p3 but I don't know what it is. I managed to find out printf("%d,", *(*(*(p3))+4)); is the answer but I still don't how does it works. I could guess (*p3)[3][2]...
hong_dynamic's user avatar
0 votes
2 answers
138 views

In Zig (and by extension C), Is pass by reference or pass by value more performant when modifying structs

Given this basic struct for 3d Vectors: pub const Vec3 = struct { x: f32 = 0, y: f32 = 0, z: f32 = 0, pub fn init(x: f32, y: f32, z: f32) Vec3 { return Vec3{ .x = x, .y = y, ....
Alex's user avatar
  • 457
0 votes
2 answers
76 views

Im trying to get user input (string) from a function, and then set a variable in my main function to their input. in C

int main(void){ int *placeholder; char userID[10] = ""; placeholder = getIdentity(); userID = *placeholder; } int getIdentity(){ static char userin[] = ""; printf("...
Thomas DeLise's user avatar

1
2 3 4 5
1134