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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…