

Mecanisme de transmitere a parametrilor
Presentation
•
Computers
•
10th - 11th Grade
•
Medium
Marilena Vilciu
Used 5+ times
FREE Resource
6 Slides • 14 Questions
1
Mecanisme de transmitere a parametrilor funcțiilor C++
Valoare și referință

2
3
Parametrii actuali la transmiterea prin valoare
expresii ex: dubleaza(b+1)
variabile ex: dubleaza(a)
constante ex: dubleaza(5)
4
Multiple Select
int f (int x){
x++;
return x;
}
Cum pot apela funcția?
f(10);
cout<<f(10);
f(a);
f(b+5)
cout<<f(c);
5
Multiple Select
void f (int x){
x++;
}
Cum pot apela funcția?
f(10);
cout<<f(10);
f(a);
f(b+5)
cout<<f(5);
6
Parametrii actuali la transmiterea prin referință
Practic, funcția crează un alias al parametrului actual transmis prin referință, deci trebuie să fie stocat undeva, să aibă o adresă.
Doar variabile pot fi parametri referință
ex: dubleaza(a), nu dubleaza(b+1) sau dubleaza(10)
7
8
Multiple Select
int f (int &x){
x++;
return x;
}
Cum pot apela funcția?
f(10);
cout<<f(10);
f(a);
f(b+5)
cout<<f(c);
9
Multiple Choice
void f (int x){
x++;
}
Rulez codul
x=6; f(x);
cout<<x;
Ce se va afișa?
6
7
x
10
Multiple Choice
void f (int &x){
x++;
}
Rulez codul
x=6; f(x);
cout<<x;
Ce se va afișa?
6
7
x
11
Multiple Choice
void f (int x, int &y){
x++; y++;
}
Rulez codul
x=y=6; f(x,y);
cout<<x<<' '<<y;
Ce se va afișa?
6 7
7 7
6 6
7 6
12
Multiple Choice
void f (int &x, int &y){
x++; y++;
}
Rulez codul
x=y=6; f(x,y);
cout<<x<<' '<<y;
Ce se va afișa?
6 7
7 7
6 6
7 6
13
Multiple Choice
void f (int x, int y){
x++; y++;
}
Rulez codul
x=y=6; f(x,y);
cout<<x<<' '<<y;
Ce se va afișa?
6 7
7 7
6 6
7 6
14
Multiple Choice
void f (int &x, int y){
x++; y++;
}
Rulez codul
x=y=6; f(x,y);
cout<<x<<' '<<y;
Ce se va afișa?
6 7
7 7
6 6
7 6
15
Multiple Choice
int f(int a){
a=a%10;
return a;
}
Dacă a=2021, ce va afișa secvența
cout<<f(a)<<' '; cout<<a;
1 1
1 2021
202 202
202 2021
16
Multiple Choice
___________{
a=a%10;
}
Ce antet ar putea avea funcția pentru ca în a să rămână doar ultima sa cifră?
void f(int a)
int f(int a)
void f(int &a)
17
Multiple Choice
___________{
int aux;
aux=a;
a=b;
b=aux;
}
Ce antet ar putea avea funcția pentru a interschimba a și b?
void f(int a, int b)
void f(int &a, int b)
void f(int a, int &b)
void f(int &a, int &b)
18
Multiple Choice
___________{
while (a>9) a=a/10;
}
Ce antet ar putea avea funcția pentru ca în a (pozitiv) să rămână doar prima sa cifră?
void f(int a)
int f(int a)
int f(int &a)
void f(int &a)
19
Multiple Choice
___________{
while (a>9) a=a/10;
return a;
}
Ce antet ar putea avea funcția pentru a returna doar prima cifră a lui a (pozitiv), fără a modifica a?
void f(int a)
int f(int a)
int f(int &a)
void f(int &a)
20
Mecanisme de transmitere a parametrilor funcțiilor C++
Valoare și referință

Show answer
Auto Play
Slide 1 / 20
SLIDE
Similar Resources on Wayground
14 questions
Angle Relationships
Presentation
•
10th - 12th Grade
16 questions
Geometry - 5.5 Inequalities in One Triangle
Presentation
•
10th Grade
15 questions
ROTASI
Presentation
•
11th Grade
17 questions
USO DE C,S,Z
Presentation
•
10th Grade
13 questions
Piecewise Functions
Presentation
•
10th - 11th Grade
13 questions
Tangent Properties
Presentation
•
10th - 11th Grade
15 questions
Speed
Presentation
•
10th Grade
14 questions
Camera Parts
Presentation
•
10th - 12th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Computers
10 questions
Fact Check Ice Breaker: Two truths and a lie
Quiz
•
5th - 12th Grade
10 questions
Video Games
Quiz
•
6th - 12th Grade
10 questions
Test Your Knowledge with 15 Fun Trivia Questions
Interactive video
•
6th - 10th Grade
15 questions
Memorial Day Trivia
Quiz
•
KG - 12th Grade
12 questions
Name that Candy
Quiz
•
KG - 12th Grade
20 questions
Guess The App
Quiz
•
KG - Professional Dev...
30 questions
K/H Final Review Part 1
Quiz
•
9th - 12th Grade
40 questions
NCFE Earth and Environmental Science Released Test
Quiz
•
9th - 12th Grade