473,749 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1882
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(becaus e 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(becaus e 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*******@gmai l.comwrote in news:1182868592 .336797.296630
@x35g2000prf.go oglegroups.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(becaus e 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
19114
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
9
1978
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, display, it always gives me 4202717 for the element number 1 in the array, While 0,2,3 .. are all ok. It seems to be skipping number 1 in the array. anyone ? problem is in createTime() function I am using visual c++
6
3668
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 the example shows a System.IndexOutOfRangeException being thrown. However, in the very next section (Jagged arrays) they have warning section that says "Java programmers take note: While Java does bounds checking on array use, C# does not." ...
5
2186
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 Contains property before adding. Question. Can I use an Array for this or should I use an
2
4756
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. Suppose I need an S1 x S2 x ... x Sn dimensional array A. I can have the same layout in memory by reversing the dimensions: A... == A(Sn,...,S1) where I used the C/C++ notation for row-major and the matlab notation
28
25510
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 A { int n; int m;
26
6291
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 of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
2
3731
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 open the picture in the form, the write to file function(btn_SaveClick) doesn't work anymore. Every time I click the save button, nothing changed in the file. But before the execution of open picture, it works normally. Why does that happen? thanks
4
1752
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 1 Here comes the confusion part. Array<int32*iarrayPtr = new Array<int32>(10);
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.