Noob question

S

Stefan Ram

Stang1 said:
a[b++] = 0;

Inserted directly in front ofe »}« in

int main() { int a[ 1 ]; int & b = a[ 0 ]; }

it should invoke undefined behavior upon execution.

There also are other contexts, where it will not
invoke undefined behavior.
 
G

Guest

Stang1 said:
a[b++] = 0;

Perfectly legal, and often used in cycles.

int b=0;

while (b<10)
a[b++]=0;
a[b=c+d] = 0;

This is legal too. But sure very, very inelegant to see and understand.

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/CM/CC/E/IT/LS/M d-(--) C++++$ UBL++++$ P++++ L+++++$ E--- W+++ w--
PS+++ PE-- Y++ PGP+++ R++ tv-- b++>+++ D+ G>+++ e++>+++++ h* r++ z+++
------END GEEK CODE BLOCK------
 
D

doublemaster007

Stang1 said:
a[b++] = 0;

Perfectly legal, and often used in cycles.

int b=0;

while (b<10)
        a[b++]=0;
a[b=c+d] = 0;

This is legal too. But sure very, very inelegant to see and understand.

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/CM/CC/E/IT/LS/M d-(--) C++++$ UBL++++$ P++++ L+++++$ E--- W+++ w--
PS+++ PE-- Y++ PGP+++ R++ tv-- b++>+++ D+ G>+++ e++>+++++ h* r++ z+++
------END GEEK CODE BLOCK------

But i have one more doubt..
Here value of b is taken for index or result of this operation (b=c
+d), that is true or false??
 
B

Bo Persson

Stang1 said:
a[b++] = 0;

Perfectly legal, and often used in cycles.

int b=0;

while (b<10)
a[b++]=0;
a[b=c+d] = 0;

This is legal too. But sure very, very inelegant to see and
understand.

--

But i have one more doubt..
Here value of b is taken for index or result of this operation (b=c
+d), that is true or false??

The value of b *is* the result of b=c+d, so there is no difference.


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top