0
Can we create an array of type string?
6 Respuestas
+ 8
Sure. For example:
#include <iostream>
using namespace std;
int main() {
string days[] = {"Sunday", "Monday", "Tuesday", "Wedensday", "Thursday", "Friday", "Saturday"};
cout << days[4];
return 0;
}
+ 1
Yes
+ 1
yes why not!
+ 1
you are wrong ahmed in your syntax you puted 3 elements in a 2 elements array you should put s [3]
but index will be 2 because index will start from ( 0,1,2)
0
ahmed, like Mohammed said, you allocated space for an array with 2 elements in it, Not three.
Also, if you declare an array,and also initialize its elements in the same line, there's no need to enter the array size.. for instance: "int a[] = {1, 2};" instead of "int a[2] = {1, 2};"
- 4
of course , you can ... for example :
string s[2]= {"ahmed","mohamed","Ali"};