uninitialised variable but NO error

G

geek.arnuld

this is the programme: [1]

#include <iostream> // std::cout

int main()
{
int sum;
std::cout << sum << "\n";
}


when i compile it using gcc 4.1.2, i get this:

----------------------------------------------------------------------------
[unix@arch cpp]$ g++ first.cpp -o first
[unix@arch cpp]$ ./first
sum is: -1208774992
[unix@arch cpp]$
-----------------------------------------------------------------------------


i think the programme is wrong BUT why this does not give any error
like "uninitialised variable"?



--
http://arnuld.blogspot.com/
Linux registered user #439610
http://counter.li.org/

[1] http://home.no.net/dubjai/win32cpptut/html/w32cpptut_01_02_02.html
 
S

Salt_Peter

this is the programme: [1]

#include <iostream> // std::cout

int main()
{
int sum;
std::cout << sum << "\n";

}

when i compile it using gcc 4.1.2, i get this:

----------------------------------------------------------------------------
[unix@arch cpp]$ g++ first.cpp -o first
[unix@arch cpp]$ ./first
sum is: -1208774992
[unix@arch cpp]$

Because its not the compiler's responsability.
It should however generate a warning and you can have the compiler
generate an error instead (with the appropriate options).
--http://arnuld.blogspot.com/
Linux registered user #439610http://counter.li.org/

[1]http://home.no.net/dubjai/win32cpptut/html/w32cpptut_01_02_02.html
 
J

John Ratliff

this is the programme: [1]

#include <iostream> // std::cout

int main()
{
int sum;
std::cout << sum << "\n";
}


when i compile it using gcc 4.1.2, i get this:

If you have more questions about gcc, it would be best to ask them in a
gcc specific newsgroup. This newsgroup is for standard C++ language
questions.

g++ should warn you if you turn on warnings. g++ -W -Wall -O2 first.cpp
gives me a possibly uninitialized warning for your program.

--John Ratliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top