Recent Posts

Wednesday 24 January 2018

what is one dimensional array


Array is collection of similar type of data type.In the previous post we learn about what is array.
In this post we learn what is one dimensional array

topics we will learn are:
  1. What is one dimensional array.
  2. How to declare one dimensional array.
  3. How to initialize one dimensional array.
Before discuss about one dimensional array we should know what is array and how to declare array.If you don't know you can Read what is array.

What is one dimensional array:
  1. One dimensional array have single row and multiple columns.
  2. For accessing any element in one dimensional array we have to write Array name followed by element number or index number or subscript number.
  3. If we don't specify index number then the first element value will be accessed.


How to declare One dimensional Array:

To declare one dimensional array we have to write data type followed by array name followed by size of array in square bracket([ ]).you can see the below example:

Syntax:     data type array name[size of Array];
Example:  int number[5];


How to initialize One dimensional Array:

We can assign the values to array elements at the time of declaration of array.all values are separated by comma(,).you can see the below example:

Syntax:     data type array name[size of Array]={set of values};
Example:  int number[5]={2,4,6,8,10};

Example:program to input five numbers and print it in reverse order:

#include<stdio.h>
void main()
{
    int a[5],b;
    printf("type 5 numbers");
    for(b=0;b<=4;b++)
    {
        scanf("%d",&a[b]);
    }
    printf("\n in reverse order");
    for(b=4;b>=0;b--)
    {
    printf("\n%d ",a[b]);
    }

}


Output:

type 5 numbers:
2
4
6
8
10

in reverse order:
10
8
6
4
2

Explanation:

  1. When the above program executed first the array 'a'  is declared in memory with size of 5 elements.
  2. To input values loop is placed.
I hope you will understand about one dimensional array.If you like this post please share on social media.

0 comments:

Post a Comment

Followers

Popular Posts

Categories

social media

Text Widget

Powered by Blogger.

About Me

My name is junaid khan and i am a full time blogger and author of a blog tutorial called tutorialpointsolution.

String function

In the previous post we learn about what is String .we know that string is a collection of two or more characters.In string we can store al...

Search This Blog

Technology

Adbox

Recent Post

Breaking

Recent In Internet

Comments

Facebook

Pages

Comments

Pages

Recent

Pages

Technology