Size

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 5
Reputation: Faramba is an unknown quantity at this point 
Solved Threads: 0
Faramba Faramba is offline Offline
Newbie Poster

Size

 
0
  #1
Nov 29th, 2004
Are the following array declarations valid, if not why?: "i'm confused!"
const int SIZE=4;
void main()
{
int a[SIZE]= {0,2,4,6};
static int b[SIZE]={0,2,4,6,8};
int x[SIZE-5];
int d[SIZE*2];
. . .
. . .
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Size

 
0
  #2
Nov 29th, 2004
>>static int b[SIZE]={0,2,4,6,8};
SIZE = 4; b[SIZE] has 5 elements - not good

>>int x[SIZE-5];
SIZE-5 = -1. You cannot declare an array with negative dimention.

Also, int main () , not void main ().
And, for defining the size of an array, I prefer #define SIZE X instead const int SIZE=X,
Last edited by frrossk; Nov 29th, 2004 at 4:56 am. Reason: forgetting something
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Size

 
0
  #3
Nov 29th, 2004
#define is old C style syntax, in C++ const is preferred.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 2
Reputation: Richard Wong is an unknown quantity at this point 
Solved Threads: 0
Richard Wong Richard Wong is offline Offline
Newbie Poster

Re: Size

 
0
  #4
Nov 29th, 2004
Originally Posted by Faramba
Are the following array declarations valid, if not why?: "i'm confused!"
const int SIZE=4;
void main()
{
int a[SIZE]= {0,2,4,6}; ---------------(1)
static int b[SIZE]={0,2,4,6,8};
int x[SIZE-5];
int d[SIZE*2];
. . .
. . .
}

You can re-write the statement (1) as follows:
int a[] = {0,2,4,6};
void main()
{

...

}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC