Arrays in the C language are a set of homogenous data types stored at the contiguous memory location. We can define one array variable to describe individual variables rather than specifying separate variables. An index lets you access a distinct element in an array.
We can declare an array in the c language in the following way:
The array size must be a positive integer constant, and the type can be any valid C data type.
data_type array_name[array_size];
Now, let us see the example to declare the array:
int marks[5];
The index of each element is the easiest way to initialize an array. We use the index to initialize each element of the array. Consider the following example. Array Size must be a positive integer constant, and type can be any valid C data type.
#include<stdio.h>
int main(){
int i=0;
int marks[5];//declaration of array
marks[0]=80;//initialization of array
marks[1]=60;
marks[2]=70;
marks[3]=85;
marks[4]=75;
//traversal of array
for(i=0;i<5;i++){
printf("%d \n",marks[i]);
}//end of for loop
return 0;
}
80
60
70
85
75
The c array can be initialized at the time of declaration. Let’s take a look at the code.
int marks[5]=20,30,40,50,60;
There is no need to declare the size in this situation. As a result, it might alternatively be worded as follows.
int marks[]=20,30,40,50,60;
Note: also read about the Recursive function in C & Program to check whether a number is even or odd
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…
Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute…