What is the return value in Python and C? I will explore this concept using both Python and C.
C와 파이썬 각각에서 return이란 무엇일까? 오늘은 해당 개념에 대해 설명해보고자 한다.
Basic function of the "return"
The fundamental function of the 'return' statement is to return a value from a function. I will initially explain this concept using Python.
return의 기본적인 기능은 값을 반환해주는(뱉어주는) 것이다. 먼저 파이썬을 이용해 설명해보겠다.
i=0
def test(x):
i=x*100
return x
print(test(10))
OUTPUT
10
> This is because it returns "x" value.
i=0
def test(x):
i=x*100
return i
print(test(10))
OUTPUT
1000
> This is because it returns "i" value.
"return 0;" in C
It typically marks the end of a function's execution.
C에서 사용되는 return의 추가적인 역할을 설명하고자 한다. 보통 함수가 끝났다는 말을 할 때 'return 0;'을 쓴다.
#include <stdio.h>
int main()
{
int a;
int b;
a=10;
b=100;
printf("%d\t%d\n",a,b);
return 0;
int c;
c= a+b;
printf("%d\n",c);
}
OUTPUT
10 100
> It doesn't execute any code after the line "return 0;".
If we change the line "return 0;",
#include <stdio.h>
int main()
{
int a;
int b;
a=10;
b=100;
printf("%d\t%d\n",a,b);
int c;
c= a+b;
printf("%d\n",c);
return 0;
}
OUTPUT
10 100
110