Like Tree3Likes
  • 1 Post By manasij7479
  • 2 Post By Ushakal

What's the output

This is a discussion on What's the output within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> int x = 10 ; void main( ) { int x = 20; ::x = x + ::x; ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    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.
    rags_to_riches likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21