1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Output from Source Code

Discussion in 'C' started by threewingedfury, Feb 5, 2008.

  1. threewingedfury

    threewingedfury New Member

    Joined:
    Feb 5, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi - I'm supposed to convert this to Java and considering I know nothing about C, I'm a bit lost. If I knew what the output was, it would make my world A LOT easier. Can someone give me an idea of how to compile this or what IDE to use and what I need to add to it to get it to run, or an idea of the output?

    Thanks in advance!
    Code:
    #include <stdio.h> 
    
    int global = 4; 
    
    void foo(); 
    
    main() { 
    
        int id = -2; 
        printf("main(): global = %d\n" , global) ; 
        foo(); 
        foo(); 
    
        id = fork(); 
    
        if (id != 0) { 
           global++; 
           wait(NULL); 
        } 
    
       global++; 
       printf( "main(): global = %d\n" , global) ; 
        
    } 
    
    
    void foo() { 
    
        static int staticInt = 1; 
        int localInt = 3; 
        printf("foo(): staticInt = %d \n" , staticInt) ; 
        printf("foo(): localInt = %d \n" , localInt) ; 
        staticInt++; 
        localInt++; 
    
    }
     
  2. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    If you know about function calls, global, static, and local variables, and the fork command, it is fairly straightforward to determine the output of the program, which I assume is your assignment. Look up these topics in your textbook or notes.

    Converting the program to Java seems odd to me. Does Java have a fork command? (Windows doesn't.)
     
  3. DangerDev

    DangerDev New Member

    Joined:
    Feb 6, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    u can use threading instead of multiprocessing....
     
  4. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    In place all functionalities uses by your program in c is equivalent to there in java. and For fork you can use multithreading
     

Share This Page