What you are doing is printing the value in the array at spot [3][3], which is invalid for a 3by3 array, you need to loop over all the spots and print them.

for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
        printf("%d ", array[i][j]);
    }
    printf("\n");
} 

This will print it in the following format

10 23 42
1 654 0
40652 22 0

if you want more exact formatting you'll have to change how the printf is formatted.

Answer from twain249 on Stack Overflow
Top answer
1 of 6
44

What you are doing is printing the value in the array at spot [3][3], which is invalid for a 3by3 array, you need to loop over all the spots and print them.

for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
        printf("%d ", array[i][j]);
    }
    printf("\n");
} 

This will print it in the following format

10 23 42
1 654 0
40652 22 0

if you want more exact formatting you'll have to change how the printf is formatted.

2 of 6
13

There is no .length property in C. The .length property can only be applied to arrays in object oriented programming (OOP) languages. The .length property is inherited from the object class; the class all other classes & objects inherit from in an OOP language. Also, one would use .length-1 to return the number of the last index in an array; using just the .length will return the total length of the array.

I would suggest something like this:

int index;
int jdex;
for( index = 0; index < (sizeof( my_array ) / sizeof( my_array[0] )); index++){
   for( jdex = 0; jdex < (sizeof( my_array ) / sizeof( my_array[0] )); jdex++){
        printf( "%d", my_array[index][jdex] );
        printf( "\n" );
   }
}

The line (sizeof( my_array ) / sizeof( my_array[0] )) will give you the size of the array in question. The sizeof property will return the length in bytes, so one must divide the total size of the array in bytes by how many bytes make up each element, each element takes up 4 bytes because each element is of type int, respectively. The array is of total size 16 bytes and each element is of 4 bytes so 16/4 yields 4 the total number of elements in your array because indexing starts at 0 and not 1.

🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-arrays
Arrays in C - GeeksforGeeks
Printing Array Elements 2 4 8 12 16 Printing Array Elements in Reverse 16 12 8 4 2 · The size of the array refers to the number of elements that can be stored in the array. The array does not contain the information about its size but we can extract the size using sizeof() operator.
Published   October 17, 2025
Discussions

How to print a full array?
#include void print_array(int *arr, size_t len) { putchar('{'); int i; for (i = 0; i < len - 1; i++) printf("%d, ", arr[i]); printf("%d}\n", arr[i]); } int main(void) { int arr[] = {1, 2, 3}; size_t len = 3; print_array(arr, len); return 0; } More on reddit.com
🌐 r/C_Programming
16
3
September 7, 2024
Array printing function in C
Why have the condition check in the loop? The for loop is checking the condition and will stop when it's met? You're running that check every iteration which seems wasteful More on reddit.com
🌐 r/cs50
7
1
November 28, 2020
New to C array printing weird numbers
Two problems: You're trying to loop from 0 <= i <= n+1, but the array only contains n items, so you'll only have indices 0 to n-1. Generally, we'd write this range as 0 <= i < n. sizeof an array returns its size in bytes, not elements. Since ints are (usually) 4 bytes large, you're getting 4 times the size you expect. You need to divide the size of the whole array by the size of each individual element, like so: sizeof(arr) / sizeof(arr[0]). The "weird numbers" are caused by reading memory outside of your array. What's in that memory is undefined, and you could potentially crash your program by reading too far out of bounds, since you might hit memory that doesn't belong to you. More on reddit.com
🌐 r/learnprogramming
9
0
September 22, 2021
Loop over array elements without knowing length
Either your array is static or it's dynamic. If the array is static you know its length even if you don't explicity set it to a known length. You can do this int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int ARRAYLEN = (sizeof(array) / sizeof(array[0])); Use the ARRAYLEN value in your code. If the array is dynamic (malloc(), etc) you need to keep track of the array size, there's no other way. More on reddit.com
🌐 r/arduino
22
10
September 6, 2024
🌐
Python Tutor
pythontutor.com › visualize.html
Python Tutor - Visualize Code Execution
Free online compiler and visual debugger for Python, Java, C, C++, and JavaScript. Step-by-step visualization with AI tutoring.
🌐
Reddit
reddit.com › r/c_programming › how to print a full array?
r/C_Programming on Reddit: How to print a full array?
September 7, 2024 -

In python, I would use a list to store some numbers than print all of them:
x = [1, 2, 3, 4]

print(x) #output = [1, 2, 3, 4]

How should I do it in C with an array?

Another question: is an array similar to the python lists? If not, what type would be it?;

🌐
TutorialsPoint
tutorialspoint.com › learn_c_by_examples › program_to_print_array_in_c.htm
Program to print array in C
#include <stdio.h> int main() { int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int loop; for(loop = 0; loop < 10; loop++) printf("%d ", array[loop]); return 0; }
Find elsewhere
🌐
W3Schools
w3schools.com › c › c_arrays.php
C Arrays
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A ... Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.
🌐
Quora
quora.com › How-do-you-write-a-program-in-C-to-store-elements-in-an-array-and-print-them
How to write a program in C to store elements in an array and print them - Quora
Answer (1 of 2): program in C to store elements in an array and print them : #include int main( ){ int n; printf("Enter the size of the array: "); scanf("%d", &n); // Declare an array of size n int arr[n]; printf(“\nEnter %d elements for the ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-print-array-elements-in-given-order-with-and-without-function
How to Print Array Elements in a Given Order with or without a Function
February 16, 2023 - Create an integer array. Take the array elements as input from the user and print all the array elements in the given order and later in reverse order.
🌐
JSON Formatter
jsonformatter.org › json-pretty-print
Best JSON Pretty Print Online
JSON Example with all data types including JSON Array. ... Best and Secure JSON Pretty Print works well in Windows, Mac, Linux, Chrome, Firefox, Safari and Edge.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › select-object
Select-Object (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
This example gets information about the modules used by the processes on the computer. It uses Get-Process cmdlet to get the process on the computer. It uses the Select-Object cmdlet to output an array of [System.Diagnostics.ProcessModule] instances as contained in the Modules property of each System.Diagnostics.Process instance output by Get-Process.
🌐
Scaler
scaler.com › home › topics › program to print array in c
Program to Print Array in C - Scaler Topics
April 4, 2024 - We create an array arr initially and then we iterate over all the elements of the array using the for loop and then print the ith element in the ith iteration. We can also use a while loop to print the elements of an array in C.
🌐
Medium
medium.com › @ryan_forrester_ › print-array-in-c-a-comprehensive-guide-4a2171b122e3
Print Array in C++: A Comprehensive Guide | by ryan | Medium
October 17, 2024 - Let’s consider a real-world scenario where printing arrays is crucial — analyzing sensor data: #include <iostream> #include <vector> #include <numeric> #include <algorithm> #include <iomanip> struct SensorReading { double temperature; double humidity; friend std::ostream& operator<<(std::ostream& os, const SensorReading& sr) { return os << std::fixed << std::setprecision(2) << "Temp: " << sr.temperature << "°C, " << "Humidity: " << sr.humidity << "%"; } }; void analyzeSensorData(const std::vector<SensorReading>& readings) { std::cout << "Sensor Readings:\n"; for (const auto& reading : rea
🌐
Programiz
programiz.com › c-programming › c-arrays
C Arrays (With Examples)
November 10, 2024 - Here, we have used a for loop to take five inputs and store them in an array. Then, these elements are printed using another for loop.
🌐
PREP INSTA
prepinsta.com › home › top 100 codes
Top 100 Codes » PREP INSTA
5 days ago - Calculate the sum of elements in an array : C | C++ | Java | Python ... Print all permutations of a given string in lexicographically sorted order : C | C++ | Java | Python
🌐
Glasstire
glasstire.com › home › flowers, figures & fantastical frames at the 2026 dallas art fair
Flowers, Figures & Fantastical Frames at the 2026 Dallas Art Fair | Glasstire
1 week ago - This sort of piece isn’t typically in the gallery’s wheelhouse, but I love it when a dealer has something completely off the wall because they are in love with the work. The print was dated to Dürer’s lifetime, and was everything you’d want from one of his pieces — fine linework, drama, angels, landscape, the whole nine yards.
🌐
Quora
quora.com › How-do-I-print-out-an-array-in-C
How to print out an array in C - Quora
Answer (1 of 8): This is a simple program to create an array and then to print it's all elements. Now, just know about arrays. Arrays are the special variables that store multiple values under the same name in the contiguous memory allocation. Elements of the array can be accessed through their...
🌐
w3resource
w3resource.com › c-programming-exercises › array › c-array-exercise-1.php
C Program: Read and Print elements of an array - w3resource
Write a C program to input elements into an array dynamically using malloc() and print the array without using indexing.
🌐
LabEx
labex.io › tutorials › cpp-printing-array-elements-in-c-96204
Printing Array Elements in C++ - Programming Fundamentals
In this modified code, we have added a variable named max to store the maximum element of the array. We then use a for loop to iterate through the array and compare each element with the current value of max. If the current element is larger than max, the value of max is updated. Finally, we print the value of max.