Skip to main content
St Louis

Back to all posts

How to Print A 3D Array In C++?

Published on
9 min read
How to Print A 3D Array In C++? image

Best 3D Printers and Accessories to Buy in March 2026

1 Creality 3D Printer Tool Kit, 74Pcs 3D Printing Tool Wrap Kit Assembly/Removal/Filament Cutting Set 3D Printer Accessories for All FDM Printers Cleaning Finishing Printing

Creality 3D Printer Tool Kit, 74Pcs 3D Printing Tool Wrap Kit Assembly/Removal/Filament Cutting Set 3D Printer Accessories for All FDM Printers Cleaning Finishing Printing

  • VERSATILE TOOL SET FOR ALL 3D PRINTING NEEDS COMPLETE KIT TO ASSEMBLE, CLEAN, AND REFINE YOUR 3D CREATIONS.

  • PRECISION EDGING WITH 360° CHAMFER KNIFE PERFECTLY REFINE EDGES OF MODELS FOR A PROFESSIONAL FINISH.

  • QUICK NOZZLE CLEANING FOR HASSLE-FREE PRINTING EFFICIENT TOOLS TO KEEP NOZZLES UNCLOGGED AND PRINTING SMOOTH.

BUY & SAVE
$29.99 $35.99
Save 17%
Creality 3D Printer Tool Kit, 74Pcs 3D Printing Tool Wrap Kit Assembly/Removal/Filament Cutting Set 3D Printer Accessories for All FDM Printers Cleaning Finishing Printing
2 68Pcs 3D Printer Tools Kit with Storage Case, 3D Printer Accessories - Deburring Tool, 3D Printer Removing Scrapers, Metal Files, Brushes, Hand Drill, Tweezers, for Bambu Lab, Ender 3, Kobra, etc.

68Pcs 3D Printer Tools Kit with Storage Case, 3D Printer Accessories - Deburring Tool, 3D Printer Removing Scrapers, Metal Files, Brushes, Hand Drill, Tweezers, for Bambu Lab, Ender 3, Kobra, etc.

  • COMPLETE 68-IN-1 KIT: ALL ESSENTIAL 3D PRINTING TOOLS IN ONE PACKAGE!

  • PRECISION SCRAPERS: FLAWLESS REMOVAL FOR PERFECT 3D PRINTED MODELS.

  • DURABLE CASE & WARRANTY: ORGANIZE TOOLS EASILY WITH A 1-YEAR GUARANTEE!

BUY & SAVE
$33.99 $38.59
Save 12%
68Pcs 3D Printer Tools Kit with Storage Case, 3D Printer Accessories - Deburring Tool, 3D Printer Removing Scrapers, Metal Files, Brushes, Hand Drill, Tweezers, for Bambu Lab, Ender 3, Kobra, etc.
3 3D Printer Tools Kit Essential, 3D Printing Tools Kit, 3D Printer Accessories, Deburring Tool, Wire Cutter, Drill, Scraper for Remove, Smoothing, Finishing, Deburring, Craving, Drilling

3D Printer Tools Kit Essential, 3D Printing Tools Kit, 3D Printer Accessories, Deburring Tool, Wire Cutter, Drill, Scraper for Remove, Smoothing, Finishing, Deburring, Craving, Drilling

  • 56 ESSENTIAL TOOLS FOR EVERY 3D PRINTING NEED COMPREHENSIVE KIT FOR ALL POST-PRINTING TASKS-BE PREPARED!

  • ACHIEVE PROFESSIONAL-GRADE FINISHES EASILY SPECIALIZED TOOLS FOR FLAWLESS PRINTS AND PRECISION CRAFTSMANSHIP.

  • ROBUST AND PORTABLE FOR ON-THE-GO PROJECTS DURABLE CONSTRUCTION AND LIGHTWEIGHT DESIGN FOR ULTIMATE FLEXIBILITY.

BUY & SAVE
$27.99 $35.99
Save 22%
3D Printer Tools Kit Essential, 3D Printing Tools Kit, 3D Printer Accessories, Deburring Tool, Wire Cutter, Drill, Scraper for Remove, Smoothing, Finishing, Deburring, Craving, Drilling
4 3D Printer Tools Kit, 34pcs 3D Printer Accessories for All FDM/SLA Printers Includes Nozzle Cleaning Tools, Removal Scrapers, Finishing Tools, 5 Types of Files,Brushes, Wire Cutter, Engraving Knife

3D Printer Tools Kit, 34pcs 3D Printer Accessories for All FDM/SLA Printers Includes Nozzle Cleaning Tools, Removal Scrapers, Finishing Tools, 5 Types of Files,Brushes, Wire Cutter, Engraving Knife

  • COMPREHENSIVE 3D TOOL KIT FOR ENHANCED PRINTING EFFICIENCY
  • NOZZLE CLEANING SOLUTION TO ENSURE SMOOTH EXTRUSION EVERY TIME
  • DURABLE STORAGE BAG KEEPS TOOLS ORGANIZED AND READY TO USE
BUY & SAVE
$19.79 $21.99
Save 10%
3D Printer Tools Kit, 34pcs 3D Printer Accessories for All FDM/SLA Printers Includes Nozzle Cleaning Tools, Removal Scrapers, Finishing Tools, 5 Types of Files,Brushes, Wire Cutter, Engraving Knife
5 50Pcs 3D Printer Tool Kit & Accessories for All FDM/SLA Printers, Includes Nozzle Cleaning Kit, Scraper, Deburring Tool, Files, Brushes - Complete Starter Kit with Case

50Pcs 3D Printer Tool Kit & Accessories for All FDM/SLA Printers, Includes Nozzle Cleaning Kit, Scraper, Deburring Tool, Files, Brushes - Complete Starter Kit with Case

  • COMPLETE 50-PIECE SET: ALL ESSENTIALS FOR 3D PRINTING IN ONE KIT.
  • PRECISE FINISHING TOOLS: ACHIEVE PROFESSIONAL RESULTS WITH EASE.
  • USER-FRIENDLY DESIGN: PERFECT FOR BOTH BEGINNERS AND EXPERTS ALIKE.
BUY & SAVE
$20.99 $25.99
Save 19%
50Pcs 3D Printer Tool Kit & Accessories for All FDM/SLA Printers, Includes Nozzle Cleaning Kit, Scraper, Deburring Tool, Files, Brushes - Complete Starter Kit with Case
6 Auziya 45 Pcs 3D Printer Tool Kit, 3D Printer Accessories Includes Nozzle Cleaning Kit, Deburring Tool, Files, Pliers, Removal Scrapers Suitable for 3D Print Removing, Cleaning, Finishing

Auziya 45 Pcs 3D Printer Tool Kit, 3D Printer Accessories Includes Nozzle Cleaning Kit, Deburring Tool, Files, Pliers, Removal Scrapers Suitable for 3D Print Removing, Cleaning, Finishing

  • COMPREHENSIVE 45-PIECE TOOLKIT FOR ALL 3D PRINTING NEEDS.
  • DURABLE, HIGH-QUALITY TOOLS ENSURE LONG-LASTING PERFORMANCE.
  • CONVENIENT WATERPROOF BAG FOR EASY CARRYING AND STORAGE.
BUY & SAVE
$19.99 $21.99
Save 9%
Auziya 45 Pcs 3D Printer Tool Kit, 3D Printer Accessories Includes Nozzle Cleaning Kit, Deburring Tool, Files, Pliers, Removal Scrapers Suitable for 3D Print Removing, Cleaning, Finishing
7 LBOKLING 5 Inch Micro Flush Cutter, 2 Pack Small Wire Cutters Spring Loaded Cutting Pliers, Wire Cutters for Jewelry Making, Soft Copper Wire, Floral, Electronics, Model Craft, Heating Wire, 3D Print

LBOKLING 5 Inch Micro Flush Cutter, 2 Pack Small Wire Cutters Spring Loaded Cutting Pliers, Wire Cutters for Jewelry Making, Soft Copper Wire, Floral, Electronics, Model Craft, Heating Wire, 3D Print

  • COMPACT & PORTABLE: EASILY CUTS 12 AWG WIRES FOR VERSATILE TASKS.
  • DURABLE STEEL CONSTRUCTION: HIGH-QUALITY STEEL WITHSTANDS FREQUENT, TOUGH USE.
  • ERGONOMIC GRIP: REDUCES FATIGUE FOR COMFORTABLE OPERATION DURING EXTENDED USE.
BUY & SAVE
$4.99
LBOKLING 5 Inch Micro Flush Cutter, 2 Pack Small Wire Cutters Spring Loaded Cutting Pliers, Wire Cutters for Jewelry Making, Soft Copper Wire, Floral, Electronics, Model Craft, Heating Wire, 3D Print
+
ONE MORE?

To print a 3D array in C++, you can use nested for loops. Here's an example of how you can achieve this:

#include

const int ROWS = 3; const int COLS = 4; const int DEPTH = 2;

int main() { int arr[ROWS][COLS][DEPTH] = { {{1, 2}, {3, 4}, {5, 6}, {7, 8}}, {{9, 10}, {11, 12}, {13, 14}, {15, 16}}, {{17, 18}, {19, 20}, {21, 22}, {23, 24}} };

// Printing the 3D array
for (int i = 0; i < ROWS; i++) {
    for (int j = 0; j < COLS; j++) {
        for (int k = 0; k < DEPTH; k++) {
            std::cout << arr\[i\]\[j\]\[k\] << " ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}

return 0;

}

In this example, we have a 3D array arr with dimensions 3x4x2. We initialize it with some values for demonstration purposes. Then, using nested for loops, we iterate through each element of the array and print its value.

The outermost loop (i) iterates over the rows of the array. The middle loop (j) iterates over the columns, and the innermost loop (k) iterates over the depth. Inside the innermost loop, we print the value of each element.

NOTE: This code assumes a fixed size for the 3D array. If you're working with dynamic arrays, you'll need to modify the code accordingly.

How to find the maximum value in a 3D array in C++?

To find the maximum value in a 3D array in C++, you can iterate through all the elements of the array and keep track of the maximum value encountered.

Here's an example code that demonstrates how to find the maximum value in a 3D array:

#include using namespace std;

const int SIZE_1 = 3; // size of the first dimension const int SIZE_2 = 4; // size of the second dimension const int SIZE_3 = 5; // size of the third dimension

int findMaxValue(int arr[SIZE_1][SIZE_2][SIZE_3]) { int maxVal = arr[0][0][0]; // assume the first element is the maximum

// Iterate through each element of the array
for (int i = 0; i < SIZE\_1; i++) {
    for (int j = 0; j < SIZE\_2; j++) {
        for (int k = 0; k < SIZE\_3; k++) {
            if (arr\[i\]\[j\]\[k\] > maxVal) {
                maxVal = arr\[i\]\[j\]\[k\];
            }
        }
    }
}

return maxVal;

}

int main() { int arr[SIZE_1][SIZE_2][SIZE_3] = { {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}, {{21, 22, 23, 24, 25}, {26, 27, 28, 29, 30}, {31, 32, 33, 34, 35}, {36, 37, 38, 39, 40}}, {{41, 42, 43, 44, 45}, {46, 47, 48, 49, 5}, {51, 52, 53, 54, 55}, {56, 57, 58, 59, 60}} };

int maxVal = findMaxValue(arr);
cout << "Maximum value in the array: " << maxVal << endl;

return 0;

}

In the above example, the findMaxValue function takes a 3D array as input and returns the maximum value. The main function initializes a sample 3D array and calls the findMaxValue function to find the maximum value. Finally, the maximum value is printed to the console.

What is the syntax for accessing elements in a 3D array?

To access elements in a 3D array, you need to provide the indices for each dimension of the array. The syntax is as follows:

array[index1][index2][index3]

Here, "array" is the name of the 3D array, and "index1", "index2", and "index3" are the indices representing the element's position in the respective dimensions.

What is a jagged 3D array in C++?

In C++, a jagged 3D array is a multidimensional array where each row can have a different number of columns. This means that the array is not necessarily a perfect rectangular shape, but rather a jagged or uneven structure. It allows for flexibility in terms of the number of elements in each row or column.

To create a jagged 3D array, you first declare the array and then allocate memory for each row individually. Each row can have different sizes, depending on your needs. Here's an example of a jagged 3D array:

#include

int main() { int rows = 3;

// Declare 3D array
int\*\*\* jaggedArray = new int\*\*\[rows\];

// Allocate memory for each row
jaggedArray\[0\] = new int\*\[4\];
jaggedArray\[1\] = new int\*\[2\];
jaggedArray\[2\] = new int\*\[3\];

// Initialize 3D array with values
jaggedArray\[0\]\[0\] = new int\[3\];
jaggedArray\[0\]\[1\] = new int\[4\];
jaggedArray\[0\]\[2\] = new int\[2\];
jaggedArray\[0\]\[3\] = new int\[1\];

jaggedArray\[1\]\[0\] = new int\[2\];
jaggedArray\[1\]\[1\] = new int\[4\];

jaggedArray\[2\]\[0\] = new int\[3\];
jaggedArray\[2\]\[1\] = new int\[1\];
jaggedArray\[2\]\[2\] = new int\[2\];

// Assign values to each element
jaggedArray\[0\]\[0\]\[0\] = 1;
jaggedArray\[0\]\[0\]\[1\] = 2;
jaggedArray\[0\]\[0\]\[2\] = 3;

// ... assign values to other elements

// Access and print values
std::cout << jaggedArray\[0\]\[0\]\[0\] << "\\n";  // Output: 1

// ... access and print other elements

return 0;

}

In this example, the jagged 3D array has 3 rows. The first row has 4 columns, the second row has 2 columns, and the third row has 3 columns. Each element in the array can be accessed and manipulated using the appropriate indices.

How to concatenate 3D arrays in C++?

You can concatenate 3D arrays in C++ by creating a new 3D array and copying the elements from the original arrays into the new array. Here's an example code snippet that demonstrates the process:

#include

int main() { // Define the original arrays int arr1[2][2][2] = { {{1, 2}, {3, 4}}, {{5, 6}, {7, 8}} };

int arr2[2][2][2] = { {{9, 10}, {11, 12}}, {{13, 14}, {15, 16}} };

// Determine the dimensions of the original arrays int rows = sizeof(arr1) / sizeof(arr1[0]); int cols = sizeof(arr1[0]) / sizeof(arr1[0][0]); int depth = sizeof(arr1[0][0]) / sizeof(int);

// Create a new array with increased depth int newArr[rows][cols][depth + 2];

// Copy elements from arr1 to newArr for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { for (int k = 0; k < depth; k++) { newArr[i][j][k] = arr1[i][j][k]; } } }

// Copy elements from arr2 to newArr for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { for (int k = 0; k < depth; k++) { newArr[i][j][k + depth] = arr2[i][j][k]; } } }

// Print the concatenated array for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { for (int k = 0; k < depth + 2; k++) { std::cout << newArr[i][j][k] << " "; } std::cout << std::endl; } std::cout << std::endl; }

return 0; }

In this example, we create two 2x2x2 arrays arr1 and arr2. To concatenate them, we create a new array newArr with increased depth to accommodate the elements from both arr1 and arr2. We then copy the elements from arr1 to newArr, followed by copying the elements from arr2 to newArr. Finally, we print the concatenated newArr to verify the concatenation.

How to initialize a 3D array in C++?

To initialize a 3D array in C++, you can follow these steps:

  1. Declare the 3D array with the desired size of each dimension:

int array3D[SIZE1][SIZE2][SIZE3];

Replace SIZE1, SIZE2, and SIZE3 with the desired sizes for each dimension.

  1. Use nested loops to iterate through each element in the array and assign it a value:

for(int i = 0; i < SIZE1; i++) { for(int j = 0; j < SIZE2; j++) { for(int k = 0; k < SIZE3; k++) { array3D[i][j][k] = value; } } }

Replace "value" with the desired initial value for each element.

Alternatively, you can initialize the array with specific values directly at the time of declaration using curly braces:

int array3D[SIZE1][SIZE2][SIZE3] = { { {val11, val12, val13}, {val21, val22, val23}, ... }, { {val31, val32, val33}, {val41, val42, val43}, ... }, ... };

Replace [SIZE1][SIZE2][SIZE3] with the desired sizes for each dimension and replace val11, val12, val13, etc., with the desired initial values for each element.

Note: Ensure that the values provided in the initializer match the specified array dimensions.

How to resize a 3D array in C++?

In C++, you cannot directly resize a 3D array because arrays have a fixed size at compile time. However, you can simulate resizing by creating a new 3D array with the desired dimensions, copying the elements from the old array to the new one, and then deleting the old array. Here's an example of how you can resize a 3D array:

#include

// Function to resize a 3D array void resizeArray(int***& array, int oldSizeX, int oldSizeY, int oldSizeZ, int newSizeX, int newSizeY, int newSizeZ) { // Create a new 3D array with the desired dimensions int*** newArray = new int**[newSizeX]; for (int i = 0; i < newSizeX; i++) { newArray[i] = new int*[newSizeY]; for (int j = 0; j < newSizeY; j++) { newArray[i][j] = new int[newSizeZ]; } }

// Copy elements from the old array to the new one
int copySizeX = std::min(oldSizeX, newSizeX);
int copySizeY = std::min(oldSizeY, newSizeY);
int copySizeZ = std::min(oldSizeZ, newSizeZ);
for (int i = 0; i < copySizeX; i++) {
    for (int j = 0; j < copySizeY; j++) {
        for (int k = 0; k < copySizeZ; k++) {
            newArray\[i\]\[j\]\[k\] = array\[i\]\[j\]\[k\];
        }
    }
}

// Delete the old array
for (int i = 0; i < oldSizeX; i++) {
    for (int j = 0; j < oldSizeY; j++) {
        delete\[\] array\[i\]\[j\];
    }
    delete\[\] array\[i\];
}
delete\[\] array;

// Update the array pointer to the new array
array = newArray;

}

int main() { // Example usage int*** array = new int**[2]; for (int i = 0; i < 2; i++) { array[i] = new int*[3]; for (int j = 0; j < 3; j++) { array[i][j] = new int[4]; } }

// Resize the array from 2x3x4 to 3x4x5
resizeArray(array, 2, 3, 4, 3, 4, 5);

// Clean up memory
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
        delete\[\] array\[i\]\[j\];
    }
    delete\[\] array\[i\];
}
delete\[\] array;

return 0;

}

In this example, the resizeArray function takes in the old array, its dimensions, and the desired new dimensions. It creates a new 3D array called newArray with the new dimensions. Then, it copies the elements from the old array to the new array. Finally, it deletes the old array and updates the array pointer to point to the new array.

Note that this example assumes that the original array is dynamically allocated using the new keyword. If you have a static or stack-allocated array, you cannot resize it.