cs31 lecture 17

Int sometimes functions functions 60 exiting a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nt setANumber(42)
; setANumber(42)
; std::cout << anumber << std::endl; std::cout return 0; return } 58 Calling a function x Syntax: <function name> ([arg1] [,arg2])
 x Functions are expressions of their return type Ex: a function returning int can be used in an int expression x Be careful: void is not an expression type! Cannot put a function of void type in an expression x All arguments must be passed, and of matching type x Arguments may be evaluated in any order 59 Exiting a function x The ‘return xxx’ statement will exit the function The x For void functions, ‘return’ exits the function x The end of the control flow in the function is also the end The of the function of x For functions returning data, all paths in the control flow For that leads to the end of the function must lead to a return statement statement x Sometimes, the compiler may add ‘return xxx’ for int Sometimes, functions functions 60 Exiting a function x The ‘void exit(int val)
’ function exits all functions (including The main)
 when executed main)
 x break and continue do not exit a function, they only affect break the immediat...
View Full Document

Ask a homework question - tutors are online