当前位置:网站首页>Return keyword

Return keyword

2022-07-06 22:31:00 It's Beichen not too PI acridine

return keyword

return Used to terminate a function and return the following value to the caller of the function .

return Keyword exit function running at the same time , What kind of data is returned to the function ? What kind of data is it ? yes int type ?char type ? still void type ?
Actually ,return The data type returned is determined by the function definition , When defining a function , Yes “ Return data type ” Such a property , It determines return Data type returned .

return (Val);// This bracket can be omitted . But generally do not omit , Especially when returning the value of an expression .

return What can be returned ? Here's an example :

char * Func(void)
{
    
	char str[30];return str;
}

str It's a local variable , In stack memory , stay Func Released at the end , So back str Will lead to mistakes .
return Statement cannot return to point to “ Stack memory ” Of “ The pointer ”, Because there is a function in the body is automatically destroyed at the end of .

Is there a problem with this statement ? If there is no problem , What is the return ?

return ;

There is no problem with the statement .
But there is a premise , Is in void This can only be used in functions of type , The function is to end this function , The statements after this statement are not executed .

原网站

版权声明
本文为[It's Beichen not too PI acridine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061439469365.html