is this possible ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

is this possible ?

int f [4]; cin>>f; is this array can hold 5 data but the data is that i will enter is 1.. i will use this code for airline reservation ticket

23rd Oct 2016, 3:06 PM
KG Feignh
KG Feignh - avatar
4 Answers
+ 3
When you declare your array, the number in the brackets is the number of elements in that array. The index starts at 0 and goes up to the number of elements minus 1. For your example, you declared an array with four elements. The indexing for that array is 0 to 3, which is four numbers: 0, 1, 2, 3. As Petr said, you have to fill the entire array with a for loop and same for displaying it.
23rd Oct 2016, 3:34 PM
Zeke Williams
Zeke Williams - avatar
+ 2
It is not possible You can use this: for(int i=0;i<4,i++) cin>>f[i]; Btw it hold only 4 values, with indexes form 0 to 3
23rd Oct 2016, 3:18 PM
Petr Hatina
Petr Hatina - avatar
0
but my lecture says that array start with 0
23rd Oct 2016, 3:22 PM
KG Feignh
KG Feignh - avatar
0
thank you for that idea .. i learn from it
23rd Oct 2016, 3:37 PM
KG Feignh
KG Feignh - avatar