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

I mean that i is incremented by 1 right, then how does ptr + i equals ith block of memory since int size is 4? int i, n; printf("Enter the number of Integers: "); scanf("%d&...
0x0pralad0x0'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
3 votes
4 answers
143 views

I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it. workspace_file->flc = malloc(sizeof(char *)); ...
Ho1Ai's user avatar
  • 39
1 vote
1 answer
121 views

I'm trying to write a queue that will store strings. Using GDB I can tell that I make a memory allocation error in the function resizeQueue. Here's the exact message: Program received signal SIGTRAP, ...
user31051859's user avatar
1 vote
1 answer
73 views

I am planning to make a Linear Regression model using C. It takes a set of m points as input from stdin using scanf. The points are defined as a struct: typedef struct{ double x; double y; } ...
Nirav Pandey's user avatar
0 votes
0 answers
103 views

Consider the following excerpt from Prometheus source code: func (ls Labels) String() string { var bytea [1024]byte // On stack to avoid memory allocation while building the output. b := bytes....
vtm11's user avatar
  • 409
1 vote
1 answer
91 views

I have a parent struct that has an array of child structs and the length of it, and within each child struct is an array of numbers and the length of it. all of the arrays are defined using pointers ...
Sterticc's user avatar
-1 votes
1 answer
136 views

I am trying to solve LeetCode 2487: Remove Nodes From Linked List, and I’ve implemented a solution in C++ that first reverses the list, then removes nodes that have a greater value node to their left (...
notSukuna's user avatar
5 votes
0 answers
121 views

I would like to frequently allocate and reuse buffers of up to multiple hundreds of MBs. I want to use a memory pool for this because I know the target machines possess enough memory capacity and I ...
Clutterhead's user avatar
2 votes
0 answers
77 views

I’m developing a custom OS and facing a chicken-and-egg problem with my page frame allocator. I need to map a specific page, but if the corresponding PML4 entry is NULL, I must allocate a PDPT. ...
Viliam Holly's user avatar
4 votes
2 answers
206 views

I am trying to correctly handle user input in C, particularly when reading a file path from the user. However, I have some concerns: How do I refactor this code to handle dynamic memory allocation. ...
tr41z's user avatar
  • 43
3 votes
2 answers
149 views

I'm just starting to program in c, so i don't have much experience with manual memory management. Coming from python, syntax like the following is very pleasant: import numpy as np b = np.array([1,2,...
Alberto Méndez -Dettmer Muñoz's user avatar
0 votes
1 answer
87 views

Goal: Enable user to input a huge amount of data (text type) in cmd. I have somewhere in my code a function input_buff(buf, CMD_SIZE); buf is dynamically allocated buffer and CMD_SIZE is fixed to 16. ...
user avatar
1 vote
1 answer
67 views

I wrote this code in C where you type a word or sentence (char s[]) and two numbers (l for left and r for right). It's supposed to seperate the string into 3 parts: 1. from start to position l-1 ,2. ...
Mr BaW's user avatar
  • 39
0 votes
2 answers
335 views

So we have 2 main memories stack and heap. When I create an simple object of class(A obj) which is heap allocated and if we have data members which require heap allocation and stack allocation then ...
shubham kakade's user avatar
0 votes
2 answers
122 views

The following code allocates 256 bytes for a character array and then replaces the space with \0 (similar to what strtok and strsep do). #include <stdlib.h> #include <string.h> int main() ...
9-Pin's user avatar
  • 482
-2 votes
1 answer
161 views

What is the main difference between using the new operator to create an array with trailing parentheses and without? That is, the difference between the following declarations void* ptr = new int[5]();...
Synex's user avatar
  • 213
-1 votes
1 answer
51 views

i have problems with distributing template. i tried with different syntax, but not a successful way with the error text: error C2512: 'node': no appropriate default constructor available for the code ...
Mohamed Elhaware's user avatar
3 votes
2 answers
144 views

What is the principle of std::string concatenation in C++ ? How does it works in memory allocation ? I found out while exploring a leetcode card that in Java: "concatenation works by first ...
Rimso's user avatar
  • 33
0 votes
1 answer
233 views

I have a Arduino script running for a few years now. Recently I wanted do some minor updates, but I've been running into problems ever since. Even when I run the older version (the version running ...
Paul Heuts's user avatar
1 vote
1 answer
111 views

I am writing code to take in a weighted adjacency list in C. Each edge is stored in the form of a struct. I created an array of pointers where each pointer leads to the list for a node. Here's what I ...
Jennie's user avatar
  • 35
3 votes
4 answers
181 views

Say I have a function that allocates some struct (object) and has to allocate additional data when setting its fields. Since each allocation can fail, the object creation may only partly succeed. What ...
user6163780's user avatar
1 vote
1 answer
129 views

Consider the following minimal working example: program p type t integer,allocatable::i end type type(t),allocatable::o allocate(o) deallocate(o) end This code was ...
V T's user avatar
  • 337
10 votes
2 answers
1k views

We need to separate allocation and initialization of some heap storage. Unfortunately, client code uses delete p; to delete the pointer. If we had control of the deletion, we could allocate with ::...
Max's user avatar
  • 181
0 votes
2 answers
158 views

Consider this code: typedef struct my_struct { int a; int b; int c; } my_struct; void some_function(my_struct *value) { // do something } int main(void) { for (;;) { some_function(&...
Cyril's user avatar
  • 3,167

1
2 3 4 5
84