Thread: What's the output

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    5

    What's the output

    Code:
    #include<iostream.h> 
        int x = 10 ; 
        void main( ) 
        { 
             int x = 20; 
             ::x = x + ::x; 
             cout <<x; 
        }

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Chennai, India
    Posts
    2,642
    Why don't you test yourself and find out ?
    Did you forget that we're not compilers ?

    ALSO
    The program will fail to compile if you use a decent compiler.
    (NOT the one from the stone ages that you're using)

    It is
    int main(), not void .
    <iostream> instead of <iostream.h>
    std::cout instead of cout. (or a using namespace std; statement)
    Last edited by manasij7479; 08-24-2011 at 12:41 PM.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    48
    First of all, it wont compile: it's std::cout (or you can put "using namespace std;" after the include) and you should be including <iostream>, not <iostream.h>.

    I'm not going to tell you the output would be if it compiled, because it looks like this is homework or something and there's a policy about not handing out homework answers on this forum. Either deduce what the output should by taking into consideration the scope of each x variable, or get it to compile by fixing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 09:46 PM
  4. output a string to a standard output
    By sh4k3 in forum C Programming
    Replies: 3
    Last Post: 06-15-2007, 05:59 AM
  5. Replies: 3
    Last Post: 02-19-2003, 07:34 PM

Tags for this Thread