The basics of programming in c++ for beginners

Tasks and Solutions: Pointers C ++

Тему Указатели в C мы рассмотрели в двух статьях:

–  Part 1: C++ Pointers

– Part 2: C++ Pointers

Теперь вам придется много практиковаться, чтобы закрепить знания и до конца разобраться. Решим несколько задач для начала.

1.  The task of the elementary, but it requires a good understanding of what pointers. Dan pointer: double **p = 0; Perform the following tasks (solutions can execute within the function main):
* create a design, shown in Figure;
* print number, specified in the box, the screen;
* then delete all dynamic objects.

with the solution of the problem, C ++ pointers

Yet again – We are looking for the shortest solution. Author:  

2. Объявите указатель на массив типа double и предложите пользователю выбрать его размер. Далее напишите четыре functions: первая должна выделить память для массива, second– заполнить ячейки данными, третья – показать данные на экран, четвертая – освободить занимаемую память.  The program should prompt the user to continue working (создавать новые динамические массивы ) or withdraw from the program.

3. Объявите указатель на массив типа int и выделите память память для 12-ти элементов. It is necessary to write a function, которая поменяет значения четных и нечетных ячеек массива. Например есть массив из 4-х элементов:

задачи и решения указатели c++

задачи и решения указатели c++

4.  Declare and populate a two-dimensional array of dynamic random numbers from 10 to 50. Показать его на экран. Для заполнения и показа на экран написать отдельные функции. (подсказка: функции должны принимать три параметра – указатель на динамический массив, количество строк, количество столбцов).  The number of rows and columns the user selects.

40 thoughts on “Tasks and Solutions: Pointers C ++

  1. double* giveMemoryToArr(double* startPtr, int sizeOfArr);
    void fillArr(double* ptrArr, int sizeOfArr);
    void showArr(double* ptrArr, int sizeOfArr);
    double* freeMemory(double* ptrArr);
    Please explain these lines,why do we take a pointer to double,why void.

    1. pointer must be of the same type it points to/stored type. just unnecessarily complicated the beginner 2 task. the array itself is a pointer. void because there is no need to return anything after the function has run, it's the same as return 0;

Leave a Reply

Your email address will not be published. Required fields are marked *