19
Partial Initialization of Arrays
During Declaration
•Thestatement:
intlist[10]={0};
declareslisttobeanarrayof10
componentsandinitializesallofthemtozero
•Thestatement:
intlist[10]={8,5,12};
declareslisttobeanarrayof10
components,initializeslist[0]to8,
list[1]to5,list[2]to12andallother
componentsareinitializedto0
20
Partial Initialization of Arrays
During Declaration (continued)
•Thestatement:
intlist[]={5,6,3};
declareslisttobeanarrayof3components
andinitializeslist[0]to5,list[1]to6,and
list[2]to3
•Thestatement:
intlist[25]={4,7};
declaresanarrayof25components;
initializeslist[0]to4andlist[1]to7;all
othercomponentsareinitializedto0
21
Some Restrictions on Array
Processing
•Considerthefollowingstatements:
•C++doesnotallowaggregateoperationson
anarray:
•Solution:
22
Some Restrictions on Array
Processing (continued)
•Thefollowingisillegaltoo:
•Solution:
23
Address of an Array in Memory
24
Searching an Array for a
Specific Item
•Practical Example?
Sample Run
Enter 10 integers:
2 56 34 25 73 46 89 10 5 16
Enter the number to be searched: 25
25 is found at position 3