943,972 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1926
  • C++ RSS
Nov 29th, 2004
0

Size

Expand Post »
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];
. . .
. . .
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Faramba is offline Offline
5 posts
since Nov 2004
Nov 29th, 2004
0

Re: Size

>>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
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004
Nov 29th, 2004
0

Re: Size

#define is old C style syntax, in C++ const is preferred.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 29th, 2004
0

Re: Size

Quote 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()
{

...

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Richard Wong is offline Offline
2 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Really Weird Error... Fibonacci Nums
Next Thread in C++ Forum Timeline: Can any1 tell me whatz wrong in this program...this does not show the output!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC