C Exercises
Home
'C' Exercises ▼
Basic C Programming
If-else Statements in C
Loops in C
Arrays in C
Pattern Programs in C
Series Programs in C
String in C
Switch-case in C
Functions in C
Pointers in C
Bitwise operators in C
File handling in C
Tricky Programs in C
Projects in C ▼
C Project-1
C Project-2
Java ▼
Java Introduction
Arrays in Java
Basic Java Examples
Generics in Java
Constructor in Java
OOP's Interview Questions
Courses
Tools
▼
Array in C Definition, Syntax, Working, Advantages & Disadvantages
Definition : Array is collection of similar data types. That means using array we can store similar type of elements.
In short array is a variable which can store multiple values. For example, if you want to store 100 and more intigers, then you need to create an array for it.
Syntax:
Advantages of array:
Arrays are used to store collection of data.
Array is used when there is need to use many variable's of the same datatype.
Memory allocated dynamically in the array which will help to save memory.
It use less amount of code.
We can access any element easily using array name and index.
Disadvantages of array:
Array is static structure which means array is of fixed size.
Using array we can store only similar type of elements.
Java program to print given elements:
This program shows you working of array. In this program we will print given elements, on output screen using for loop . This program shows value stored in array with their position.
#include <stdio.h>
void main ()
{
int arr[5]={10,20,30,40,50},i;
printf ("Elements in array are:\n" );
for (i=0;i<5;i++)
{
printf ("arr[%d]=%d\n" ,i,arr[i]);
}
}
Above program shows the following output:
No comments:
Post a Comment
If you have any doubts, please discuss here...👇