• 0

Dynamic Array in C++ (Please help me I don't understand some code line, somebody please explain them for me)


Question

This is a function to insert A Number at A Position in a dynamic array ;

1/ I don't understand from the line "moveCount". What is moveCount for , and, Why move count = size - index;

2/ what in the function "memmove" in c++

3/ could you please explain the codes from the line "ARROW" to the end ?

Thank you so much for helping me ( I am just a stupid child trying to mess around with code :) )

Untitled.png

Edited by crop_duster

1 answer to this question

Recommended Posts

  • 0

The moveCount var is basically getting the size of the array minus the index of where you want to insert the new value within the array (the function name is DynamicArray::insertAt after all), the if statement makes sure it is an array and if, it's not using memmove to increase the size allocated.

 

http://www.cplusplus.com/reference/cstring/memmove/

 

  Quote

memmove

void * memmove ( void * destination, const void * source, size_t num );

Move block of memory

Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.

The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data.

The function does not check for any terminating null character in source - it always copies exactly num bytes.

To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least numbytes.

 

Parameters

destination

Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.

source

Pointer to the source of data to be copied, type-casted to a pointer of type const void*.

num

Number of bytes to copy.
size_t is an unsigned integral type.

Expand  

 

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.