Let us learn the Concept of Arrays in C programing language

Today we will learn a new concept that is found in most of the programing language. It is one of the essential topics and it helps alot when it comes to coding with real life solutions.

I am talking about Arrays. Arrays are collection of similar types of data together under a single entity or name. This definition can vary from different programing languages.

For example in C the array can either be containing numbers or characters but in python array can contain different data types together.

Let us look at the program itself :

image.png

Copy the basic code from below :

#include <stdio.h>

int main() {
int array[5];
printf("Enter 5 numbers: ");
for (int i = 0; i < 5; i++) {
scanf("%d", &array[i]);
}
printf("You entered: ");
for (int i = 0; i < 5; i++) {
printf("%d ", array[i]);
}
return 0;
}

Here our array is on int type that means it will store integer values like 1,2,3,4,5 etc. We have used a for loop and this is the way we define array's elements.

The output of the array program will depend on the input provided by the user.

Screenshot 2023-01-15 224819.png

In this example, the user enters the numbers 1 2 3 4 5 as input, and the program stores them in an array called "array". Then the program prints the numbers in the array.

It's important to note that the program uses a for loop to iterate through the array and print each element. And also the input format should be the same as the format that is mentioned in the scanf statement.

It's also worth noting that the numbers in the array are separated by spaces, this may vary depending on how the program is written.

What do you think will happen if we enter a character at the time of input. Here is what i saw in the output.

image.png

Can anyone tell what is the logic behind this output ?

If you also want to learn coding then find your teacher according to your language. For me i am comfortable with hindi language and follow hindi teachers.

You can refer to my teacher below in case you are also comfortable with hindi.

Source

I will soon call myself a trader and a small programmer together.

Happy trading and keep learning what you love.

Coin Marketplace

STEEM 0.20
TRX 0.14
JST 0.030
BTC 66205.77
ETH 3304.04
USDT 1.00
SBD 2.72