0
How to find the last position of an element in that array?
Char ar[10]={'1','2','3',};
7 Respostas
+ 2
//You can put values like this:
char a[] = { '1', '2', '3', '4', '5' };
or
char a[10] = { '1', '2', '3', '4', '5' };
int len= sizeof(a) / sizeof(a[0]);
//both arrays works, but first one no need loop
//len value is 5
//just need cout<<a[len-1];
//but second way need this loop why because the value for len=10 for 2nd array so need loop
So in that case, use @JaScript code to avoid printing empty character and only print last assigned value and break loop.
for(int i=len-1; i>=0;i--)
if (a[i]) {
cout<<a[i];
break;
}
+ 1
Find array length by
int len = sizeof(ar) / sizeof(ar[0]) ;
and ar[len-1] is the last value in array...
but if you declare length as 10 , then ar[9] is the last value..
if declare length as 10 then, len= 10 only with the above method.
use char ar[]={'1', '2',..... };
+ 1
Jayakrishnađźđł thank u very much
+ 1
size of the array / size of its type (you can get the second by passing one of its element â the safest being the first (index 0) element) to the sizeof function.
If you're building a class with a array as one of its members, it may make sense to add an extra int size member to your class with a getter (just don't forget to update the int whenever it makes sense)
0
Please đ Help me
0
Jayakrishnađźđł but I want to input the values in that array and find the last position of that element
0
You're welcome...