https://youtu.be/5JR5ydzEX3A?feature=shared
https://youtu.be/Pc7ain6E37I?feature=shared
return문은 함수에서 값을 반환하고 함수를 종료하는 키워드입니다.
#include <iostream>
#include <cpltasks.h>
using namespace std;
int Add(int a, int b)
{
return a + b;
}
int main()
{
int a = 5;
int b = 6;
int ret = Add(a, b);
return 0;
}
return문의 역할:
x는 0 ~ 2까지, y는 0 ~ 2까지 반복하며 2차원 배열에 순차적으로 값을 저장합니다.
#include <iostream>
using namespace std;
int main()
{
int vect[3][3] = { 0 };
int x, y;
int t = 1;
for (y = 0; y < 3; y++)
{
for (x = 0; x < 3; x++)
{
vect[y][x] = t;
t++;
}
}
return 0;
}
결과:
1 2 3
4 5 6
7 8 9
y방향이 바깥에 움직이고, x방향이 안쪽에 움직입니다. x는 2부터 0까지 움직이고, y는 0부터 2까지 움직입니다.
#include <iostream>
using namespace std;
int main()
{
int vect[3][3] = { 0 };
int x, y;
int t = 1;
for (x = 2; x >= 0; x--)
{
for (y = 0; y < 3; y++)
{
vect[y][x] = t;
t++;
}
}
return 0;
}
결과: