Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

How do you initialize matrix value in c but in pointer? void addTodo(char *todo) { int j = 0; for (j; j < strlen(todo); j++) { matrix[CurrentTodoIndex1][j] = todo[j];// I wanna ...
Star_'s user avatar
  • 1
0 votes
4 answers
116 views

I was attempting the binary tree inversion question on Leetcode https://leetcode.com/problems/invert-binary-tree/ I came up with this solution TreeNode* invertTree(TreeNode* root) { if (root ==...
Raghav Wadhwa's user avatar
1 vote
1 answer
127 views

My code should print the numbers given as command line arguments. Instead it prints random-looking values. What is going on and how can I fix it? #include <stdio.h> #include <pthread.h> #...
user31884282's user avatar
1 vote
0 answers
56 views

We are using Matlab to communicate with a C++ library, and are struggling with memory management. We create a libpointer pointing to an array, and then try to update its value in a loop. I don't think ...
RPM's user avatar
  • 1,809
2 votes
1 answer
154 views

I have 2 maps using BidBook = std::map<float, int, std::greater<>>; // price -> qty using AskBook = std::map<float, int, std::less<>>; I have a struct that contain iterator ...
Huy Le's user avatar
  • 1,979
0 votes
1 answer
78 views

I am trying to use std::map to map numerical IDs to function handlers: All function handlers take two integers and return an integer. Handler 100 would calculate the product. When preparing the map, ...
Ralf's user avatar
  • 11
3 votes
1 answer
117 views

In Rust, both references and pointers to unsized types have metadata indicating the actual type of the reference. For example, a *mut [T] consist of a pointer to the start of a slice, plus a length ...
ais523's user avatar
  • 2,352
-4 votes
1 answer
211 views

Ok so I was messing around with some OOPs in visual studio 2022 community edition in C++, when I came across such a baffling problem that I don't even know where to start searching for it. #include &...
Shay1313's user avatar
1 vote
0 answers
83 views

I am trying to learn C, and I want to specifically work with arrays and matrices as I do scientific simulations (coming from python!!). After writing few basic 1-D array codes in C, I am going for ...
Sayantan4796's user avatar
2 votes
4 answers
236 views

If two pointers are referencing the same memory location. Will it be possible to make one pointer null, if we deallocate that memory location? For example: #include <iostream> using namespace ...
GhostVaibhav's user avatar
4 votes
2 answers
224 views

I don't know how to reset the value field inside the Hello struct. It's a pointer pointed to an outside passed input argument. typedef struct Hello { void *value; } Hello; Hello* create_hello() { ...
stackbiz's user avatar
  • 1,916
4 votes
1 answer
133 views

I’m new to C and I’m trying to understand how pointers work. In this piece of code, when I run it on Python Tutor (pythontutor.com) to see how the stack and heap work, I never see the pointer being ...
Bilal's user avatar
  • 173
0 votes
0 answers
140 views

From another thread I found that indeed allocates enough storage to hold at least n elements, but it doesn't actually fill the container with any elements If elements are already allocated why ...
sat0sh1c's user avatar
0 votes
1 answer
169 views

#include <iostream> using namespace std; int* apply_all(int* arr1, int size1, int* arr2, int size2){ int* on_the_heap = new int(size1 * size2); int temp = 0; for(int i {0}...
Adepa's user avatar
  • 19
3 votes
2 answers
163 views

The code below looks crazy, because I am interested in finding out the limits of what’s possible, and it isn’t exactly what I’m doing in my real code. It compiles without warnings and works as ...
njlarsson's user avatar
  • 2,530
2 votes
3 answers
188 views

size_t hash(char const[restrict static 32]) [[reproducible]]; This is a function definition from Modern C by Jens Gustedt. I understand that this is a more preferred alternate notation to a 32 char ...
Puscas Raul's user avatar
3 votes
1 answer
93 views

A pointer can be safely cast to intptr_t (or uintptr_t) and back (on platforms where those types exist), but what about casting a pointer-to-intptr_t into pointer-to-pointer and using that to modify ...
njlarsson's user avatar
  • 2,530
0 votes
0 answers
85 views

I want to write (in C) library routines which create and use arrays of items whose size is unknown at compile time. So I create an 'array': void *item_array=malloc(arr_sz*item_sz); and a function ...
chaoticbob's user avatar
22 votes
1 answer
2k views

#include <stddef.h> #include <stdlib.h> int main(void) { const size_t length = 10000; double* a = malloc(length * sizeof *a); double* first = a; double* last = a + length-1; ...
Rasmus's user avatar
  • 383
4 votes
3 answers
170 views

void do_something(void *data) { t_my_type *mt; mt = (t_my_type *)data; //mt->my_var = ... //... } void do_something2(t_my_type *mt) { //mt->my_var = ... //.....
Atti's user avatar
  • 91
1 vote
1 answer
163 views

I'm trying to wrap my head around the reachability precondition of std::launder in the context of (abstract) c++ pointer model. Here's a code snippet that makes me confused as to whether this ...
Die4Toast's user avatar
  • 123
9 votes
1 answer
230 views

I was doing some reading on std::launder, and I thought of a scenario that the standard didn't seem to address. cppreference.com defines std::launder(T *p) like this: Formally, given the pointer p ...
Brian Smith's user avatar
3 votes
2 answers
152 views

I'm trying to understand how pointer arithmetic works in C. Say if I have two arrays, one static and the other dynamic like so, int a[10]; int * b = malloc(sizeof(int) * 10); And lets assume each ...
js980's user avatar
  • 35
1 vote
3 answers
83 views

I have pointer into a delay line that I wish to update. If the pointer (p) goes past the end of the buffer, I wish to wrap around to the start plus some value. _Complex float buffer[BUF_LEN]; ...
james's user avatar
  • 21
1 vote
1 answer
77 views

I have an array of pointers to structs in C as typedef struct{ int elem1; char *elem2; ... }example_t; example_t *array[MAX_SIZE]; I did generic functions for add or delete pointers to ...
Daniel Muñoz's user avatar

1
2 3 4 5
1147