New answers tagged pointers
Score of 0
0
votes
c freeing char pointer not working after first time
There are many cases of confusion in your code:
[major] missing headers: always post a complete program, missing header files may be a source of problems.
[minor] *(newNumber + (newLen - 1)) = *...
Score of 0
0
votes
When to use Box instead of reference?
References don't "own" their values, so they are fine for parameters, but no use for long-term storage or return values.
Box "owns" the value, so it can be stored long term, ...
Score of 3
3
votes
Accepted
Kotlin/Native/cinterop pointer to custom class
In Kotlin/Native, you cannot declare var with fields in classes that inherit from CPointed. Such classes should reflect the C‑structure in its original form, without unnecessary fields. Otherwise, the ...
Score of 0
0
votes
Understanding and relationship between Box, ref, & and *
Box isn't really a pointer
Box is a wrapper around a pointer that automatically destroys the object and frees the allocation. Similar to unique_ptr in C++ but unlike unique_ptr a valid Box cannot be ...
Score of 0
0
votes
C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array
$ #Sample code here
$ /usr/bin/cat "79986370.c"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct mystruct
{
char *...
Score of 4
4
votes
C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array
sizeof(pstring) is the size of a pointer not string.
(the_data[index]->mychar)=ouputs undefined behavior due to segfault
p_mystruct the_data[2]; declares an array of uninitialized pointers.
Score of 6
6
votes
C assign to char * in a struct in a pointer to the struct from a char * function parameter called with a char array
Your code has undefined behavior as a result of a NULL pointer dereference.
The variable the_data is an array of struct pointers. Because it is declared at file scope without an initializer, the ...
Score of 0
0
votes
Identifying what child class object a base class pointer is pointing at
You were trying to apply a C-style cast. But what you failed to do naively, is actually doable if you use dynamic_cast :
void identifyChild(Base *obj)
{
auto as_child1 = dynamic_cast<Child1*>...
Top 50 recent answers are included
Related Tags
pointers × 57361c × 28442
c++ × 22997
arrays × 10973
struct × 4643
function × 3028
string × 2724
reference × 1955
memory × 1843
linked-list × 1809
malloc × 1727
char × 1368
vector × 1367
class × 1343
memory-management × 1342
segmentation-fault × 1331
go × 1066
casting × 1064
c# × 1049
multidimensional-array × 1035
c++11 × 907
constants × 813
structure × 793
dynamic-memory-allocation × 766
function-pointers × 749