|
-
Dec 17th, 2003, 06:26 PM
#1
Thread Starter
Fanatic Member
stupid C++
newbie here to C++
can someone tell my this would fail??
p1=p1+4
p2=p1-1
for ( source = 17; source != p2; source--)
it works if i said
for ( source = 17; source != 3; source--)
-
Dec 17th, 2003, 06:35 PM
#2
-
Dec 18th, 2003, 09:19 AM
#3
Thread Starter
Fanatic Member
-
Dec 18th, 2003, 09:52 AM
#4
yay gay
Originally posted by jsun9
i believe
You declared the variables, but there is NOTHING inside.
How are you excepting that : p1 = nothing + 4 will ever work?
\m/  \m/
-
Dec 18th, 2003, 12:06 PM
#5
Thread Starter
Fanatic Member
wha? how am I supposed to increment p1 by 4?
-
Dec 18th, 2003, 12:09 PM
#6
yay gay
Originally posted by jsun9
wha? how am I supposed to increment p1 by 4?
What you have to understand is that int p1 is ONLY a int and contains NOTHING inside because you still didnt set it to anything..so if it is NOTHING you can't increment it. Simply put you must do int p1=0; or whatever..
I think this is quite obvious..
\m/  \m/
-
Dec 18th, 2003, 01:48 PM
#7
Thread Starter
Fanatic Member
-
Dec 18th, 2003, 02:04 PM
#8
Hyperactive Member
For future reference, only global variables (variables declared outside a function, including the main() function) are automatically initialized. Everything else is filled with whatever ramdom junk is in memory (including values of previous variables).
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Dec 19th, 2003, 11:37 AM
#9
Not even global variables are initialized. There is no automatic initialization for primitives anywhere in C++.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 19th, 2003, 02:01 PM
#10
Hyperactive Member
Originally posted by CornedBee
Not even global variables are initialized. There is no automatic initialization for primitives anywhere in C++.
You sure about that?
http://cplus.about.com/library/weekly/aa101902k.htm
Global integers(for example) are consistently initialized to zero in both GCC and MVC++.NET.
Last edited by Comreak; Dec 19th, 2003 at 02:08 PM.
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Dec 19th, 2003, 02:23 PM
#11
Ok, you're right. They are initialized.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 19th, 2003, 07:51 PM
#12
yay gay
Why global vars are initialized and the others are not?
\m/  \m/
-
Dec 20th, 2003, 06:53 AM
#13
Because the C++ standard says so?
I guess it's a speed issue. Local variables would have to be initialized every time the function is called, global vars get initialized once by the exe loader.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 20th, 2003, 07:42 PM
#14
Originally posted by PT Exorcist
You declared the variables, but there is NOTHING inside.
How are you excepting that : p1 = nothing + 4 will ever work?
Well actually they contain whatever was in those 4 particular bytes of memory occupied by the integer last. Junk basically, stuff like:
-839295
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|