Computer Science, asked by abhishek6712, 2 months ago

Aron declared an array as: int marks[8]={50, 56, 80, 75}; What would be the Fifth element of the array? *​

Answers

Answered by pragatibhatt2922
1

Answer:

Explanation:

datatype   array_name [ array_size ] ;

For example, take an array of integers 'n'.

int n[6];

n[ ] is used to denote an array 'n'. It means that 'n' is an array.

So, int n[6] means that 'n' is an array of 6 integers. Here, 6 is the size of the array i.e. there are 6 elements in the array 'n'.

array of integers in C

We need to give the size of the array because the complier needs to allocate space in the memory which is not possible without knowing the size. Compiler determines the size required for an array with the help of the number of elements of an array and the size of the data type present in the array.

Here 'int n[6]' will allocate space to 6 integers.

We can also declare an array by another method.

int n[ ] = {2, 3, 15, 8, 48, 13};

In this case, we are declaring and assigning values to the array at the same time. Here, there is no need to specify the array size because compiler gets it from { 2,3,15,8,48,13 }.

Index of an Array

Every element of an array has its index. We access any element of an array using its index.

Pictorial view of the above mentioned array is:

element 2 3 15 8 48 13

index 0 1 2 3 4 5

0, 1, 2, 3, 4 and 5 are indices. It is like they are identity of 6 different elements of an array. Index always starts from 0. So, the first element of an array has a index of 0.

Index of an array starts with 0.

We access any element of an array using its index and the syntax to do so is:

array_name[index]

For example, if the name of an array is 'n', then to access the first element (which is at 0 index), we write n[0].

Here,

n[0] is 2

n[1] is 3

n[2] is 15

n[3] is 8

n[4] is 48

n[5] is 13

elements of array in C

n[0], n[1], etc. are like any other variables we were using till now i.e., we can set there value as n[0] = 5; like we do with any other variables (x = 5;, y = 6;, etc.).

Similar questions