NO

Author Topic: Comma as a sequence point in for loop  (Read 2452 times)

Tapasweni Pathak

  • Guest
Comma as a sequence point in for loop
« on: January 01, 2014, 12:32:16 PM »
I have a line of code,
Code: [Select]
int numbers[n];
for( i = 0; i < n; ++i, numbers [i] = i );



is , a sequence point here?
or is it undefined?
Code: [Select]
++i, numbers[i] = i;
comma here, is acting as an operator or separator, inside the for loop?
« Last Edit: January 01, 2014, 12:35:33 PM by Tapasweni Pathak »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Comma as a sequence point in for loop
« Reply #1 on: January 01, 2014, 06:50:55 PM »
I have a line of code,
Code: [Select]
int numbers[n];
for( i = 0; i < n; ++i, numbers [i] = i );



is , a sequence point here?
What you means for sequence point?
Code: [Select]
++i, numbers[i] = i;
comma here, is acting as an operator or separator, inside the for loop?
The comma is acting as 'C' comma operator: separates two statements discarding the result of the first one.
Look here for more details.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide