![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
assignment question
I'm confused by this assignment statement. Why is there two variables on the right, and what would this statement be equivilent to?
Node newNode = variable1, variable2; |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
It is equivalent to:
Node newNode = variable1; Node variable2; |
|
|
|
|
|
#3 | |
|
Sexy Programmer
|
Quote:
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Yes. Though the occurences of such a statement in the real world are few and far between, for reasons obvious.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#5 |
|
Expert Programmer
|
Just so it's crystal clear, you can think about it this way:
You can declare two or more variables on one line by separating them with a comma, for example: int one, two, three; You can also initialize the variables at the same time you declare them: int one = 1, two = 2, three = 3; |
|
|
|
|
|
#6 |
|
Sexy Programmer
|
I think though, it could save a lot of lines of code when making a program. I do initialize my variables like that when I program. Though, as said before, people who are novice at programming will be confused when reading it.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#7 |
|
Professional Programmer
|
Oh comone , how many lines of code? 2, 3 ? 10 ?
I hate when people do : int a, b, c; It's much better : int a ; // a cute comment int b ; // a cute comment int c ; // a cute comment Even if the variables have meaningful names for you, a bit of comment won't hurt.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#8 | |
|
Sexy Programmer
|
Quote:
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
Well , i didn't mean ALL the lines obviously. Just that i consider writing variables on the same line bad practice.
But hey , it's a free world ![]()
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#10 |
|
Sexy Programmer
|
it's all good!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|