0
How to get length or size of array?
i have defined array string array string s[] = {"Physics","Chemistry","Maths","English","Hindi"}; yes we know its 5 but how to get in cpp and assign to int veriable thanks.
5 Answers
+ 1
try this
int counter = 1;
while (s!=NULL){
counter++;
s++;
}
+ 1
(sizeof(s)/sizeof(*s))
Only works for 'real' arrays, not pointers.
+ 1
That's because you need (sizeof(s)/sizeof(*s))
0
int main() {
string s[]={"Physics","Chemistry","Maths","Hindi","English"};
cout <<sizeof (s)<<endl ;
j
int counter =1;
while (s!=NULL)
{counter ++;
s++;}
cout <<s<<endl ;
return 0;
}
friends i ve tried above but sizeof not giving 5 & counter is giving error
thanks
0
thanks Robobrine, it worked. i was trying sizeof(s); only. thanks both.