473,513 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with elements in array

20 New Member
I just need to set the first two elements in my array to false and the rest to true how would you do that?
Nov 21 '08 #1
5 1215
JosAH
11,448 Recognized Expert MVP
I just need to set the first two elements in my array to false and the rest to true how would you do that?
Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < array.length; i++)
  2.    array[i]= i >= 2;
  3.  
kind regards,

Jos
Nov 21 '08 #2
Ganon11
3,652 Recognized Expert Specialist
Or the slightly less confusing:

Expand|Select|Wrap|Line Numbers
  1. array[0] = array[1] = false;
  2. for (int i = 2; i < array.length; i++) {
  3.    array[i] = true;
  4. }
Nov 21 '08 #3
JosAH
11,448 Recognized Expert MVP
There was nothing confusing about it; the following might be a bit confusing to
the novice:

Expand|Select|Wrap|Line Numbers
  1. for (int i= array.length; i > 0; array[--i]= -i < ~0);
  2.  
kind regards,

Jos ;-)
Nov 21 '08 #4
Ganon11
3,652 Recognized Expert Specialist
If you notice, I never explicitly said your response was confusing. I merely stated that mine was less confusing.

This previous example is quite complicated, indeed.
Nov 21 '08 #5
JosAH
11,448 Recognized Expert MVP
If you notice, I never explicitly said your response was confusing. I merely stated that mine was less confusing.
As in "Xs dinner was less filthy as Ys dinner was"? What was filthy about Xs
dinner if Ys dinner wasn't filthy?

This previous example is quite complicated, indeed.
You ain't seen nothing yet ;-)

kind regards,

Jos
Nov 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2107
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
2
3731
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
1
5513
by: koen colen | last post by:
Hello group, I hope you guys can help me out, I am modifying a piece of code from Joe Norman, I did found the code here: http://www.intranet2internet.com/public/default.asp?PAGE=sscript&ID=3 ...
14
1690
by: Jinjun Xu | last post by:
Hi, I have an array and I want to adjust the size (remove some elements). I use the following code. Can you help me to check whether it's correct. ////////////// start int *p1 = new int; ...
3
3804
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
5
1763
by: chaching | last post by:
Please help. The code below will compile and run using the Dev C compiler, but not the Visual C++ 2005 express edition. I need it to run in the express editions. any suggestions? #include...
5
1314
by: 05l8kr | last post by:
I'm suppose to write two codes....I have some of it done, I don't think I've done it right. I'm suppose to write a program that will get from the user's keyboard one sets of numbers that will be...
0
5522
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
9999
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
7269
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,...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7394
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,...
0
7559
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...
0
5701
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,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4756
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...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
470
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...

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.