 
        
        Магистратура Языки программирования С,C++ / Как выполняются программы на C++
.pdf 
main()
foo()
bar()
Лекция 2. Как выполняются программы на C++
Устройство стека
дно стека
вершина стека
void bar( ) { int c;
}
void foo( ) { int b = 3; bar();
}
int main( ) { int a = 3; foo(); bar();
return 0;
}
| http://compscicenter.ru | 19/21 | 
 
main()
foo()
Лекция 2. Как выполняются программы на C++
Устройство стека
дно стека
вершина стека
void bar( ) { int c;
}
void foo( ) { int b = 3; bar();
}
int main( ) { int a = 3; foo(); bar();
return 0;
}
| http://compscicenter.ru | 19/21 | 
 
Лекция 2. Как выполняются программы на C++
Устройство стека
дно стека
main()
вершина стека
void bar( ) { int c;
}
void foo( ) { int b = 3; bar();
}
int main( ) { int a = 3; foo(); bar();
return 0;
}
| http://compscicenter.ru | 19/21 | 
 
main()
bar()
Лекция 2. Как выполняются программы на C++
Устройство стека
дно стека
вершина стека
void bar( ) { int c;
}
void foo( ) { int b = 3; bar();
}
int main( ) { int a = 3; foo(); bar();
return 0;
}
| http://compscicenter.ru | 19/21 | 
 
Лекция 2. Как выполняются программы на C++
| 
 | x | = | 1 | 
 | frame | 
| 
 | y | = | 2 | 
 | |
| 
 | 
 | pointer | |||
| 
 | 
 | 
 | 
 | 
 | 
stack pointer
Вызов функции
int foo(int a, int b, bool c)
{
double d = a * b * 2.71; int h = c ? d : d / 2; return h;
| } | 
 | 
| int main( ) | 
 | 
| { | 
 | 
| int x = | 1; | 
| int y = | 2; | 
| x = foo | (x, y, false); | 
| cout << | x; | 
return 0;
}
| http://compscicenter.ru | 20/21 | 
 
Лекция 2. Как выполняются программы на C++
| 
 | x = 1 | 
 | frame | 
| 
 | y = 2 | 
 | |
| 
 | 
 | pointer | |
| 
 | false | 
 | 
 | 
| 
 | 2 | 
 | 
 | 
| 
 | 1 | 
 | 
 | 
| 
 | 
 | 
 | 
 | 
stack pointer
Вызов функции
int foo(int a, int b, bool c)
{
double d = a * b * 2.71; int h = c ? d : d / 2; return h;
| } | 
 | 
| int main( ) | 
 | 
| { | 
 | 
| int x = | 1; | 
| int y = | 2; | 
| x = foo | (x, y, false); | 
| cout << | x; | 
return 0;
}
| http://compscicenter.ru | 20/21 | 
 
x = 1
y = 2
false
2
1
ret val
ret addr
registers
Лекция 2. Как выполняются программы на C++
Вызов функции
| frame | int foo(int a, | int | b, bool c) | ||
| { | 
 | 
 | 
 | ||
| pointer | 
 | 
 | 
 | ||
| double | d = | a * | b * 2.71; | ||
| 
 | |||||
| 
 | int | h = | c ? | d : d / 2; | |
return h;
}
int main( )
{
| 
 | int x = 1; | |
| 
 | int y = 2; | |
| stack | x = foo (x, y, false); | |
| 
 | ||
| cout << x; | ||
| pointer | ||
| return 0; | ||
| 
 | ||
| 
 | } | |
| 
 | 
 | 
| http://compscicenter.ru | 20/21 | 
 
x = 1
y = 2
false
2
1
ret val
ret addr
registers
d
h
Лекция 2. Как выполняются программы на C++
Вызов функции
| frame | int foo(int a, int b, bool c) | ||
| { | 
 | ||
| pointer | 
 | ||
| double | d = a * b * 2.71; | ||
| 
 | |||
| 
 | int | h = c ? d : d / 2; | |
| 
 | return h; | ||
| 
 | } | 
 | |
| 
 | int main( ) | 
 | |
| 
 | { | 
 | |
stack
pointer }
int x = 1; int y = 2;
x = foo (x, y, false); cout << x;
return 0;
| http://compscicenter.ru | 20/21 | 
 
Лекция 2. Как выполняются программы на C++
x = 1
y = 2
false
2
1
ret val
ret addr
registers
d
h
a * b = 2
frame pointer
stack pointer
Вызов функции
int foo(int a, int b, bool c)
{
double d = a * b * 2.71; int h = c ? d : d / 2; return h;
| } | 
 | 
| int main( ) | 
 | 
| { | 
 | 
| int x = | 1; | 
| int y = | 2; | 
| x = foo | (x, y, false); | 
| cout << | x; | 
return 0;
}
| http://compscicenter.ru | 20/21 | 
 
Лекция 2. Как выполняются программы на C++
x = 1
y = 2
false
2
1
ret val
ret addr
registers
d = 5.42
h = 2
frame pointer
stack pointer
Вызов функции
int foo(int a, int b, bool c)
{
double d = a * b * 2.71; int h = c ? d : d / 2; return h;
| } | 
 | 
| int main( ) | 
 | 
| { | 
 | 
| int x = | 1; | 
| int y = | 2; | 
| x = foo | (x, y, false); | 
| cout << | x; | 
return 0;
}
| http://compscicenter.ru | 20/21 | 
