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
56,818
questions
2
votes
1
answer
113
views
array of pointers to pointers to integers VS pointer to pointer to array of integers
I have 3 integers A, B & C from which I make pointers that I group in an array arrayABC of pointers to pointers:
int A = 1;
int B = 2;
int C = 3;
int *ptA = &A;
int *ptB = &B;
int *ptC = &...
1
vote
1
answer
28
views
Can't put values together into struct that is initiated by pointer and malloc [duplicate]
Just a simple struct called person, inside I need to store name and age. I'm trying to dynamically allocate memory for my struct.
Without using pointer:
#include <stdio.h>
#include <stdlib.h&...
-11
votes
0
answers
63
views
What's the difference between 'ClassName* p' and 'ClassName p'? [duplicate]
Please explain to me the difference between Player p and Player* p.
Why should I write it like this:
Player *p = new Player(playwin, 1, 1, '#');
while (p->getmv() != 'x')
{
p->display();
...
0
votes
1
answer
17
views
Struct and Pointers: Please help me understand this line of code
Please help me understand what does the last line does:
int PCKT_LEN = 8192;
char buffer[PCKT_LEN];
struct iphdr *ip = (struct iphdr *) buffer;
struct udphdr *udp = (struct udphdr *) (buffer + ...
-3
votes
0
answers
122
views
Are pointers smartly allocated? [duplicate]
While learning about pointers in Uni, They taught us that pointers are allocated memory for the address to be stored. And while I was messing around with pointers and null pointers.
I noticed this ...
1
vote
0
answers
39
views
Passing an array to a function in C - array subscript vs pointer dereferencing [duplicate]
Coming from mainly Python and JavaScript
I (think I) understand that when you pass the name of an array to a function, the array is decayed to a pointer. The part that confuses me is the fact that the ...
-2
votes
0
answers
95
views
Pointer "ptr + offset" vs "&ptr[offset]" [closed]
Consider a piece of code in C as shown below
int arr[1000];
int offset = 500;
int *ptr_array = (int *)&arr[0];
int *ptr_temp1 = ptr_array + offset; // ---> method-1
int *ptr_temp2 = &...
1
vote
1
answer
128
views
Specify the type of a C++ pointer at runtime (generic pointer)
I am developing a simulation code written entirely in C++ where we use double precision for all computations. Now I want to make it configurable to use single precision if the user wants. The problem ...
1
vote
0
answers
19
views
redefine pointer to function (to a function, not an object or to a variable) inside another function [duplicate]
How can I redefine a pointer to a function inside another function?
In JS variables are passed by value and objects are passed by reference (these are pointers in some way). I thought functions were ...
2
votes
3
answers
123
views
Converting to char*** from char* [2][2]
I have the following variable
char* a[2][2] = {{"123", "456"}, {"234", "567"}};
I wanted to refer it using another variable. While the cast works, accessing ...
0
votes
1
answer
114
views
Why does defining the elements of the array b is required to get the desired output
I recently learnt about typecasting pointers. So I played around, and made this bad code:
#include <stdio.h>
int main()
{
int* a;
char b[]= "Hye";
a = (int*)&b;
*a='...
2
votes
1
answer
107
views
Is comparing two pointers to different char objects undefined in C?
This is code of memmove from https://github.com/gcc-mirror/gcc/blob/master/libgcc/memmove.c
void *
memmove (void *dest, const void *src, size_t len)
{
char *d = dest;
const char *s = src;
if (d &...
-6
votes
2
answers
71
views
malloc(): corrupted top size on deleting an entry from binary file [closed]
I AM CREATING A SCHOOL MANAGEMENT SYSTEM . WHEN I TRY TO DELETE A STUDENT AFTER ADDING ONE I AM GETTING "malloc(): corrupted top size" ERROR .CANT FIND THE REASON.I AM A BEGINNER , HELP ...
1
vote
3
answers
101
views
In C, why can a variable holding a char array be assigned to a pointer, but the address of the same pointer cannot?
Consider the following code:
char stringy[] = "There's too much confusion, I can't get no relief!";
char *pStringy;
pStringy = stringy;
This compiles -
stringy is an array of characters, ...
0
votes
0
answers
38
views
A property of Python class returns an empty numpy array with pybind11
I adopted a project that was abandoned by it's original creator on GH: pybind11 bindings for whispercpp. I had to update Python version from 3.8 to 3.11.8 in CI and discovered that some of the test ...