The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C One Dimensional Array

What Is One Dimensional Array

An array which has only one subscript is known as one dimensional array i.e) int arr[10].

c one dimensional array

Syntax - One Dimensional Array

Syntax
data_type varname[size];

Rules For Declaring One Dimensional Array

  • An array variable must be declared before being used in a program.
  • The declaration must have a data type(int, float, char, double, etc.), variable name, and subscript.
  • The subscript represents the size of the array. If the size is declared as 10, programmers can store 10 elements.
  • An array index always starts from 0. For example, if an array variable is declared as s[10], then it ranges from 0 to 9.
  • Each array element stored in a separate memory location.

Program - One Dimensional Array

In C programming, programmers can also initialize the array variable without mentioning the size of an array. The compiler will automatically deduct the size of an array.

declaration-1
int student[5] = {89, 76, 98, 91, 84};
declaration-2
int student[] = {89, 76, 98, 91, 84};
one-dimensional-array.c
#include <stdio.h>
int main()
{
int s[5] = {89, 76, 98, 91, 84}, i;
printf("\n---Students marks details--- ");
for(i = 0; i < 5; i++)
{
printf("\ns%d = %d ", i + 1, s[i]);
}
return 0;
}
  • ---Students marks details---
  • s1 = 89
  • s2 = 76
  • s3 = 98
  • s4 = 91
  • s5 = 84

Note:

The above program illustrates that the declaration and initialization of one dimensional array. The first element of an array is s[0]. The last element of an array is a[4].

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report