{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Functions and Void

Functions and Void - Functions and Void A function that...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Functions and Void A function that takes no parameters may specify void in the list of arguments EX. int f(void) <-- does not take arguments == int f() a function that returns no results also can be defined as returning void. EX. void g() // g returns no arguments What happens if there is no return type? By default, a function with no return type returns int If you have a function int xx() { return 5;} and you call xx without using the result, then the result will be discarded. Type Conversions - Assignment type conversion - Expression type conversion - Cast type conversion double d = (double)i; -Argument type conversion Conversion takes place when passing an argument to a function that takes arguments of a different type. EX: double sqrt(double); sqrt(3); <-- 3 is an int constant, when passed to sqrt, it is converted to double -Return type conversion Conversion takes place in the return statment EX: double yyy(){ int i = 5; return i; <-- converted to double before returning } Scope The scope of an identifier is the region in the program in which the identifier is visible.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}