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.

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ learn_c_by_examples โ€บ print array in c
Program to print array in C
May 2, 2016 - START Step 1 โ†’ Take an array A and define its values Step 2 โ†’ Loop for each value of A Step 3 โ†’ Display A[n] where n is the value of current iteration STOP ยท Let's now see the pseudocode of this algorithm โˆ’ ยท procedure print_array(A) ...
๐ŸŒ
w3resource
w3resource.com โ€บ c-programming-exercises โ€บ array โ€บ c-array-exercise-1.php
C Program: Read and Print elements of an array - w3resource
Read and Print elements of an array: ----------------------------------------- Input 10 elements in the array : element - 0 : 1 element - 1 : 1 element - 2 : 2 element - 3 : 3 element - 4 : 4 element - 5 : 5 element - 6 : 6 element - 7 : 7 element - 8 : 8 element - 9 : 9 Elements in array are: 1 1 2 3 4 5 6 7 8 9
๐ŸŒ
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?;

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-arrays
Arrays in C - GeeksforGeeks
Array declaration is the process of specifying the type, name, and size of the array. In C, we have to declare the array like any other variable before using it.
Published ย  October 17, 2025
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ program to print array in c
Program to Print Array in C - Scaler Topics
April 4, 2024 - Every time the while loop runs we print the ith element and update the variable i by i+1. Similar to a while loop we can also use a do while loop to print the elements of an array in C.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_arrays.php
C Arrays
To create an array, define the data type (like int) and specify the name of the array followed by square brackets [].
๐ŸŒ
W3Schools Blog
w3schools.blog โ€บ home โ€บ print an array in c
print an array in c - W3schools
December 6, 2022 - for (int i = 0; i < length; i++) { printf("%d ", arr[i]); } //Change "length" to size of your own array and rename "arr" to your own array name
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-arrays
C Arrays (With Examples)
November 10, 2024 - In this tutorial, you will learn to work with arrays. You will learn to declare, initialize and access array elements of an array with the help of examples. An array is a variable that can store multiple values.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_arrays_loop.php
C Arrays and Loops
You can use a for loop to go through the elements of an array by writing the size of the array in the loop condition (in this example the array has 4 elements, so we use i < 4). However, this is not ideal, since it will only work for arrays ...
๐ŸŒ
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...
๐ŸŒ
W3Schools Blog
w3schools.blog โ€บ home โ€บ code to print out entire array in c
code to print out entire array in c - W3schools
December 3, 2022 - [ad_1] print an array in c int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int i; for (i = 0; i
๐ŸŒ
Know Program
knowprogram.com โ€บ home โ€บ how to print an array in c
How to Print an Array in C - Know Program
March 29, 2021 - How to Print an Array in C | To print an array we need to use loops. The loop can be either for loop, while loop, or do-while loop.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ c-program-to-print-elements-in-an-array
C Program to Print Elements in an Array
April 5, 2025 - In this example, it will be from 0 to 7 ... First Iteration: for (i = 0; 0 < 5; 0++) Condition is True, so the Programming compiler will print the first element(10) in the One Dimensional Array.
๐ŸŒ
Academic Help
academichelp.net โ€บ coding โ€บ c-coding โ€บ how-to-print-an-array.html
How to Print an Array in C: Explanation&Examples
October 31, 2023 - The C programming language provides a versatile platform for various applications, from operating systems to simple algorithms. One of the foundational aspects of C programming is the management and utilization of arrays. In this article, we will delve deep into how to print an array in C using various methods, including for loops, while loops, and even recursion.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 82860-using-printf-print-out-array.html
Using printf to print out an array
I'm not use to C...I'm just trying to find a bug in someone elses C code that happens to affect my other code. Thanks (Stats is an int array) Last edited by slowcoder; 09-11-2006 at 02:05 PM. ... int i; for (i=0; i<4; i++) { printf("%d %d\n", Stats[i][0], Stats[i][1]); } Or you you want hex, then:
๐ŸŒ
w3resource
w3resource.com โ€บ c-programming-exercises โ€บ basic-declarations-and-expressions โ€บ c-programming-basic-exercises-50.php
C Program: Print the position and value of an array elements - w3resource
#include <stdio.h> #define AL 5 ... size 5 to hold floating-point numbers int i; // Prompt for user input printf("Input the 5 members of the array:\n"); // Read and store user input into the array for(i = 0; i < AL; i++) { ...
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_pointers_arrays.php
C Pointers and Arrays
Confused? Let's try to understand this better, and use our "memory address example" above again. The memory address of the first element is the same as the name of the array: int myNumbers[4] = {25, 50, 75, 100}; // Get the memory address of the myNumbers array printf("%p\n", myNumbers); // Get the memory address of the first array element printf("%p\n", &myNumbers[0]); Result: 0x7ffe70f9d8f0 0x7ffe70f9d8f0 Try it Yourself ยป ยท
๐ŸŒ
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 - In this way, we can take each value from the user and store it in our array in a sequential way. Keep in mind that the array always starts from the 0 index (the first element is at index 0, the second is at index 1, and so on). Now it is time to print all the array elements (the value that each index of the array has) in the given order.