Jump to content

Can anyone explain segmentation?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
facade626

facade626

    Newbie

  • Members
  • Pip
  • 1 posts
Hello All,

I'm trying to learn more about stack flow or process flow (i.e. Data Segment, Stack Segment, Code Segment, and the Heap Segment, FIFO, LIFO, etc, etc..... (we're using Java)). I also have an example my professor tried to explain below, but I still don’t really understand the flow really. Can anyone explain in detail what happens to get the right output…..which is 1 6 5 and 1 12 9 (I think)? Or maybe offer a website or book that better explains the process.

1. class T6
2. {
3. public int a = 1;
4. public static int b = 2;
5. public static int c = 3;
6. }

7. public static int f1(int b, int a)
8. {
9. int c;
10. c = b + a
11. return(c + a);
12. }

13. public static int f2(int c, int a)
14. {
15. c = b + a
16. b = f1(a, b)
17. return(c + a);
18. }

19. public static void main(String argv[])
20. {
21. int a, b, c;
22. a = 1; b = 2; c = 3;
23. T6 o1;
24. o1 = new T6();

25. o1.b = f1(c, a);
26. System.out.println(o1.a + “ “ + o1.b + “ “ + o1.c);

27. o1.c = f2(c, b);
28. System.out.println(o1.a + “ “ + o1.b + “ “ + o1.c);
29. }
30. }

#2
mortifera

mortifera

    Newbie

  • Members
  • Pip
  • 2 posts
The output is:
1 5 3
1 12 9

It is a bit tricky you have to be sure about the terms of "public static" and "public int".if u try to change the public members u get error "Cannot make a static reference to the non-static field"
If you want to understand this q just give the logical name for every variable and follow the program step by step.