473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

About simple confusion of array incrementation

sam
hI,
I am little confused here
See
i have
int wordlen=10;

when int s[] is array

s[wordlen-1-1]++;
whats the meaning of this
can it affects the number which are in array.
or it can just shifts from say 2 numbers(which are minused here after
each incrementation)
what i want to ask is ? is it shifting 2 numbers or it is minusing 2
numbers in array.
means can it affecting the numbers in array.

See why I am confused is the real question is here?
lets take wordlen=20 ok
and if we minusing -1-1 means -2 each time then the wordlen will be 18
is it means wordlens value will be changes to 18
or the value of array will be changes to 18 because in next iteration
(lets take more than one iteration for s[wordlen-1-1]++)
value of wordlen will be remain same because
at the start we declare
int wordlen=20;
i am quite confused but i think some you understand
in SHORT MY QUESTION IS
is incrementation affecting the value of wordlen or it can affect the
value in array means not wordlen particularly
PLease give me some explanation and make the way clear
Thanks in advance

Jun 26 '07 #1
4 1855
sam wrote:
hI,
I am little confused here
See
i have
int wordlen=10;

when int s[] is array

s[wordlen-1-1]++;
whats the meaning of this
If the line above is a question (I am used to seeing question marks
at the end of questions, but that's just me), then the answer is

post-increment the element at the index (wordlen-2) of the array
's' and discard the return value.
can it affects the number which are in array.
It should does (given that the array has more than 8 elements).
or it can just shifts from say 2 numbers(which are minused here after
each incrementation)
Shifts? I am not sure what you mean.
what i want to ask is ? is it shifting 2 numbers or it is minusing 2
numbers in array.
I have no idea what you mean here.
means can it affecting the numbers in array.
It can affecting.
See why I am confused is the real question is here?
Yes, I sure have.
lets take wordlen=20 ok
ok, 20
and if we minusing -1-1 means -2 each time then the wordlen will be 18
No, the index would be 18. 'wordlen' will stay 20.
is it means wordlens value will be changes to 18
No, it doesn't mean that.
or the value of array will be changes to 18 because in next iteration
No, it doesn't mean that either. It means the element of the 's'
array _at_ the position 18 would be incremented.
(lets take more than one iteration for s[wordlen-1-1]++)
lets
value of wordlen will be remain same because
at the start we declare
int wordlen=20;
No, not because we declare. Because the expression does not change the
value of 'wordlen'.
i am quite confused but i think some you understand
You are, yes. I understand.
in SHORT MY QUESTION IS
is incrementation affecting the value of wordlen or it can affect the
value in array means not wordlen particularly
Correct. The incrementation affecting the value in array.
PLease give me some explanation and make the way clear
Indexing operator is applied first. It returns [a reference to] the
element in the array. Then the post-increment is applied to that
element. The element is incremented.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 26 '07 #2
sam
HI,
My friend just take a look at what i am saying
s[worllen-1-1]++;
IN THIS VALUE OF ARRAY WILL BE 18
IN next iteration again value of wordlen will be worldlen(because we
are not changing the value of wordlen in iteration)
means the value of wordlen will remain 20 in next iteration also and
we are minusing 2 from this , then we get the same value inside array
that is 18
SEE HOW THIS POSSIBLE EVERY TIME IN NEXT ITERATION ALSO THE VALUE IN
ARRAY REMAIN SAME AND SO AFTER INCREMENTING SUCH ARRAY ALSO THE VALUE
CAN REMAIN SAME FOR THE NEXT ITERATION ALSO
So
This concept of mine(may be MISCONCEPT) BUT I want make clear what is
boiling in mind
Please Help me here?_?_?_
I am really confused!!!!!!!!!

Jun 26 '07 #3
sam wrote:
HI,
My friend just take a look at what i am saying
s[worllen-1-1]++;
IN THIS VALUE OF ARRAY WILL BE 18
No, the value of the _index_ will be 18.

in
s[wordlen-1-1]++;

s is the array
wordlen-1-1 is the index
s[wordlen-1-1] is an element of the array.

Since wordlen == 20, the index is 18, and you are referencing the 19th
element.
IN next iteration again value of wordlen will be worldlen(because we
are not changing the value of wordlen in iteration)
Yes.
means the value of wordlen will remain 20 in next iteration also and
we are minusing 2 from this , then we get the same value inside array
that is 18
Yes.
wordlen-1
returns a temporary whose value is 19, and subtracting 1 from that temporary
will return a new temporary whose value is 18. The computations never alter
the value of wordlen.
SEE HOW THIS POSSIBLE EVERY TIME IN NEXT ITERATION ALSO THE VALUE IN
ARRAY REMAIN SAME AND SO AFTER INCREMENTING SUCH ARRAY ALSO THE VALUE
CAN REMAIN SAME FOR THE NEXT ITERATION ALSO
No. The value of the index remains the same. The 19th element of the array,
and thus the array itself, is modified.

--
rbh
Jun 26 '07 #4
sam <sa*******@gmail.comwrote in news:1182868592.336797.296630
@x35g2000prf.googlegroups.com:
HI,
My friend just take a look at what i am saying
s[worllen-1-1]++;
IN THIS VALUE OF ARRAY WILL BE 18
IN next iteration again value of wordlen will be worldlen(because we
are not changing the value of wordlen in iteration)
means the value of wordlen will remain 20 in next iteration also and
we are minusing 2 from this , then we get the same value inside array
that is 18
SEE HOW THIS POSSIBLE EVERY TIME IN NEXT ITERATION ALSO THE VALUE IN
ARRAY REMAIN SAME AND SO AFTER INCREMENTING SUCH ARRAY ALSO THE VALUE
CAN REMAIN SAME FOR THE NEXT ITERATION ALSO
So
This concept of mine(may be MISCONCEPT) BUT I want make clear what is
boiling in mind
Please Help me here?_?_?_
I am really confused!!!!!!!!!
Unfortunately so are we. At least I'm not entirely sure what you are
attempting to do.

Let us assume an array of 3 items, and worllen is 3 (because I don't want
to write 20 array values every time....):

int worllen = 3;
int s[3];

s[0] = 0;
s[1] = 0;
s[2] = 0;

Also, let's use a loop of 10 iterations, performing your operation:
for (int i = 0; i < 10; ++i)
{
s[worllen - 1 - 1]++;
}
Since worllen isn't modified during this loop, the loop effectively
behaves as if you had written:
for (int i = 0; i < 10; ++i)
{
s[3 - 1 - 1]++;
}
And if we calculate the constant expression in there, you end up with
effectively the following loop:
for (int i = 0; i < 10; ++i)
{
s[1]++;
}
The array starts with the values: { 0, 0, 0 }.

After the first iteration, the array will contain: { 0, 1, 0 }.

After the second iteration, the array will contain: { 0, 2, 0 }.

.....

After the tenth iteration, the array will contain: { 0, 10, 0 }.


Jun 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
9
by: Ken | last post by:
I have a small program , wi tha menu (only option 1,2 and 6 are working for now) Something weird is happening, my array works to input all the data the user puts in, but whebn I choose option 2,...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
5
by: Zenobia | last post by:
Hello, I want to keep a list references to database records being accessed. I will do this by storing the record keys in a list. The list must not contain duplicate keys. So I check the...
2
by: Jef Driesen | last post by:
I'm working on a project where i need to exchange multidimensional data between C/C++ (row-major) and matlab (column-major). I understand the difference between those two mappings to linear memory....
28
by: WaterWalk | last post by:
Hi, I'm haunted by 2 questions about struct copy. Though I searched the net, but still in confusion. 1. Does struct assignment copies every member including array members? For example, struct...
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
2
by: reyalp | last post by:
I use C++ Builder to create a simple project that can open a picture and save some text information to a file My question is that: After I execute the open picture dialog(btn_OpenPicture) and...
4
by: coder_lol | last post by:
Given the template class below, please help me understand the following code behavior? Array<int32ia(10); // Array that can contain 10 int32 ia = 1; // Array element 1 set to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.