0% found this document useful (0 votes)
10 views4 pages

Array Program

Uploaded by

ravi167784
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Array Program

Uploaded by

ravi167784
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ARRAY PROGRAM

1. Print array using index number

#include <iostream>
using namespace std;
int main()
{
int arr[3];
// Inserting elements in an array
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
// Accessing and printing elements of the array
cout << "arr[0]: " << arr[0] << endl;
cout << "arr[1]: " << arr[1] << endl;
cout << "arr[2]: " << arr[2] << endl;
return 0;
}

ANSHUL JAIN
2. Access a value of array

#include<iostream>
using namespace std;
int main()
{
int a[5]={10,40,60,39,50};
cout<<"a[4]:"<<a[4];
return 0;
}
3. Calculate size of array :

#include<iostream>
using namespace std;
int main()
{
int a[6]={1,5,8,9,0,5};
cout<<"size of array"<<sizeof(a);
}

ANSHUL JAIN
4. C++ Program to Illustrate How to Find the Size of an Array
#include <iostream>
using namespace std;
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
// Size of one element of an array
cout << "Size of arr[0]: " << sizeof(arr[0]) << endl;
// Size of array 'arr'
cout << "Size of arr: " << sizeof(arr) << endl;
// Length of an array
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Length of an array: " << n << endl;
return 0;
}
5. Calculate the size of array if array is a string type

#include <iostream>
using namespace std;
int main()
{
string arr[3] = { "CSE", "AIDS", "AIML" };

ANSHUL JAIN
cout << "Size of arr[1]: " << sizeof(arr[1]) << endl;
cout << "Size of arr[]: " << sizeof(arr)<< endl;
return 0;
}

6. Calculate the size of array if array is a char type

#include <iostream>
using namespace std;
int main()
{
char arr[3] = { "CSE", "AIDS", "AIML" };
cout << "Size of arr[1]: " << sizeof(arr[1]) << endl;
cout << "Size of arr[]: " << sizeof(arr)<< endl;
return 0;
}

ANSHUL JAIN

You might also like