Advertisement
#include<iostream>
using namespace std;
int main()
{
int oneDA[4]; /* declaration of a 1-D array which will hold 4 int values*/
/* Printing all the 4 elements of this array(one-by-one) */
cout << oneDA[0] << "\n";
cout << oneDA[1] << "\n";
cout << oneDA[2] << "\n";
cout << oneDA[3] << "\n";
return 0;
}
420043
321062
419443
268675
Advertisement
Array type | Default value |
---|---|
char | Any random value within the range of char |
int | Any random value within the range of int |
float | Any random value within the range of float |
long | Any random value within the range of long |
double | Any random value within the range of double |
#include<iostream>
using namespace std;
int main()
{
int oneDA[4]; /* Array is created on the heap with size 4, to hold 4 int values */
oneDA[0]=10; /* storing 10 at index 0 in array */
oneDA[1]=20; /* storing 20 at index 1 in array */
oneDA[2]=30; /* storing 30 at index 2 in array */
oneDA[3]=40; /* storing 40 at index 3 in array */
return 0;
}
cout << array[2]; //Reading 2nd index of this array gives us a value, 30
#include<iostream>
using namespace std;
int main()
{
char array[4]; /* Array object is constructed on the heap with size 4 */
array[0]='a';
array[1]='b';;
array[2]='c';
array[3]='d';
for(int i=0; i<4; i++) /* Accessing array elements in for-loop */
{
cout << array[i] << "\n";
}
return 0;
}
a
b
c
d
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement