c – Dynamic allocation, creating and accessing of structs of same struct

Trying to learn about structures (and pointers…). As my program works, I assume it is correct but asking here to make sure. As to my understanding, malloc is used to reserve some memory for all the students. In the first for-loop, each iteration of the loop takes some input that is used to create the first student and so on… Once all students are created, these structures are same size as all of them are created using the same structure.

Could someone explaine how +i and +j is used to access each structure and why the first loop use an “&” when accessing age, and not in the second loop?

#include <stdio.h>
#include <stdlib.h>

typedef struct {
char *name;
int age;

int main() {
Student *ptr;
int amount, i, j;
printf("Amount to register: ");
scanf("%d", &amount);
ptr = (Student*) malloc(amount * sizeof(Student));
for(i = 0; i < amount; i++) {
    printf("Enter name and age: ");
    scanf("%s %d", &(ptr+i)->name, &(ptr+i)->age);
for(j = 0; j < amount; j++) {
    printf("%s %dn", &(ptr+j)->name, (ptr+j)->age);
return 0;


c++ – Dynamic allocation of array in pointer ( resize allocate array)

Dynamic allocation of array in pointer ( resize allocate array)

i am using pointer to do my homework on adding value x to any position in array and have memory leak problem in visual studio 2019.

I don’t use vectors because I haven’t learned yet.

i don’t know how to fix it??

#include <iostream>
using namespace std;
void Input_Array(int* a, int size);
void Output_Array(int* a, int size);
void resize_dynamic_arrays(int* a, int old_meory, int new_memory);
void handle(int* a, int& size, int vt, int x);
int main()
    int number_of_elements,


        cout << "Enter numer of elements you want to create :  ";
        cin >> number_of_elements;
        if (number_of_elements <= 0)
            cout << "please re-enter (Guess numer of elements > 0)" << endl;

    } while (number_of_elements <= 0);

    // if > 0
    int* p_array = new int(number_of_elements); // nothrow if dynamic memory allocate fail it return NULL in pointer p_array

    cout << "nntt INPUT ARRAY n";
    Input_Array(p_array, number_of_elements);
    cout << "nntt OUTPUT ORIGINAL ARRAY n";
    Output_Array(p_array, number_of_elements);

    cout << "nEnter the location to add : ";
    cin >> location;
    cout << "nEnter a value to add : ";
    cin >> x;

    handle(p_array, number_of_elements, location, x);
    cout << "nnttHANDLING ARRAY n";
    Output_Array(p_array, number_of_elements);

    delete() p_array;


void Input_Array(int* a, int size)
    for (int i = 0; i < size; i++)
        cout << "Element at a(" << i << ") = ";
        cin >> *(a + i);

void Output_Array(int* a, int size)
    for (int i = 0; i < size; i++)

        cout << *(a + i) << " ";


void resize_dynamic_arrays(int* a, int old_memory, int new_memory)
    int* p_temp = new int(old_memory);
    for (int i = 0; i < old_memory; i++)
        *(p_temp + i) = *(a + i);

    delete() a; // giai phong bo nho cu

    int* a_new = new int(new_memory );  // plus , minus , multiple ,... in new_memory

    for (int j = 0; j < old_memory; j++)
        *(a_new + j) = *(p_temp + j);
    delete() p_temp;


void handle(int* a, int& size, int vt, int x)
    for (int i = size - 1; i >= vt; i--)
        *(a + i + 1) = *(a + i);

    *(a + vt) = x;

    resize_dynamic_arrays(a, size, size + 1);



rest – Intuitive RESTful API design for logistics shipments availability, accept, allocation decision?

How would you do that as a website?

Would you tell your users to submit some magic content to some magic URI, or would you offer a webpage where there is a form the user can fill out and just submit?

For a RESTful API, you would describe the pages you have in your application through Media Types, and let the client navigate through the use-cases using links and forms on its own. In this case the client would not need to know URIs, HTTP Methods or what to submit beforehand, because all that is discovered on the fly.

I’m just saying that, because you (or other people reading) may be not aware, that is how it was supposed to work. If you don’t want to do that, and just want endpoints that do things, return some data, and all of that is hardcoded into the clients, then I guess there’s no real difference in any of those options. You have to read the documentation and hardcode the URIs into the client, or even generate it automatically. Would different URIs make any difference there?

operating systems – How to determine memory allocation for single level table

I received this problem on my study guide but I have no idea if I’m doing it correctly:

How much space needs to be allocated for a single-level page table for a machine with a 32 bit virtual memory address and a 4K page size?

I understand that the last 12 bits of the address is the offset but how would I determine how much space is needed?

Does using a photo from Google Photos in a Google Doc cause it to be counted twice against the storage allocation?

Photos in Google Photos count against the storage allocation for the account
(though some have a billing waiver in effect, if taken on a Pixel phone).

If such a photo is incorporated into another Google product, such as Google Docs, does each use count anew for storage? Are Pixel photos charged or free, when incorporated into a document?

Has anyone done the experiment?

allocation – How do custom allocators know which addresses of memory they can allocate?

I was looking at Rust’s Allocator trait. From my understanding, you give an allocator a length of memory and a word size to align to, and the allocator either gives you a pointer to the memory or an error. So clearly the custom Allocator is finding valid addresses in the memory somehow. How does the allocator know where in the heap it can allocate? Is there some “genesis” allocator that tells the custom Allocator which addresses it can take?

Operating Systems and Drivers | File/space allocation

A single-level indexed file system has been formatted to use 128KB (131,072 byte) clusters and 4 byte file pointers. Calculate the maximum file size that would be supported using this file system. Give your answer in gigabytes.

Unexpected HY001: Memory allocation error after MySQL upgrade

Earlier today I upgraded a db.t3.large MySQL instance on AWS from v8.0.13 to 8.0.20. I’ve seen a handful of cases where I’m seeing the error SQLSTATE(HY001): Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size. I don’t expect such an error because the config or instance type didn’t change. An example of where I’m seeing this is on the following query:

SELECT * FROM `messages`
    EXISTS (
        SELECT * FROM `updates`
            `messages`.`update_id` = `updates`.`id`
            AND `game_id` = 18
    AND `messages`.`deleted_at` IS NULL

In this query, all columns used in the order and where clauses are either foreign or primary keys with messages.deleted_at being the only exception.

In the meantime I’m going to adjust this setting in my prod environment to increase the size of the sort_buffer_size, but this change is not recommend according to a lot of stuff I’m reading so I hope it’ll temporarily resolve the issue.

C Programming Basics (memory allocation)

Assume that an integer is taking 4 bits memory to store any number.
What the value of the following expression ?
In C Programming language.

data structures – Memory allocation of priority queues

An associative dictionary is any data structure which maps keys to values. Binary search trees, hash tables, and B-trees are all examples of associative dictionaries. It is incorrect to say that an associative dictionary must be a binary search tree.

Similarly, a priority queue is any data structure which allows insertion in any order and removal in priority order. A binary heap is an example of a priority queue, but it is incorrect to say that a priority queue must be a binary heap.

There are lots of other data structures which implement priority queues, including n-ary heaps (for n greater than 2), binomial heaps, Fibonacci heaps, Brodal queues, van Emde Boas trees, and many more besides.

And that’s leaving aside the issue that a binary heap doesn’t strictly need to be stored in contiguous memory. Any storage scheme can be used as long as it can be indexed like an array and supports $O(1)$ access time.