ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
2) new to oo - have an assignment to write an object with the following conditions:
The door can have two states (open or closed)
- Create methods for finding the state of the door (open or closed)
- Create methods for opening and closing the door
State any assumptions and additional features you have made on the Door class.
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105
Rep:
Hmm i think that would cause an error. var[x]++ would return a value one higher that the one pointed to by x so if var[x] = 3 then var[x]++ would return 4
you wanna create a door class and probably have a variable "doorstatus" and two methods "void setDoorState(boolean)" "bool getDoorState(void)" setDoorState take a boolean parameter and sets the variable "doorstatus" to true or false getDoorState would just return doorstatus
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105
Rep:
eshwar are you sure that doesnt cause an error it looks like he's trying to increment a value inside an array named 3 which is an error but if he meant x[3]++ then you and i are right it would add one to the value of x arrays 4th value
Mr. Element Nine
both are same.
3[x] is same as x[3].
When it comes to 3[x]++, 3[x] is evaluated first because [] has highest precedence than ++.
So there is no problem .
3[x]++ is same as x[3]++.
what do u say. check it.
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105
Rep:
uh unless everything ive learned has been wrong, that looks like an array correct? arrays structure is var[index] and variables cant start with a number
yah what ever you said is correct. you might be thinking that X[3] as a variable name, No its not. i think you know very well variable names cant have a charcter '[' like this. valid names contain only alphabets, _ , 0....9.
and one more rule is your variable name shouldnt be started with a number.
actually X[3] is not a variable name. X is the name of array. Its the base address of array( we cant change X value). no other names are there when we declare an array as below
int X[3];
ex:
datatype X[10];
when you use X[3], it is expanded as *((datatype *)X+3)
did u get my point?
ask me if u have any doubts regarding this.
bye,
Eshwar.
Originally posted by ElementNine uh unless everything ive learned has been wrong, that looks like an array correct? arrays structure is var[index] and variables cant start with a number
They are expanded to *(argv + 1) ( for example ). The thing you do not seem to realise from that is that `argv' is in fact a number, as are all other variables. They are memory references.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.