cs31 lecture 17

stdendl stdcout 56 types and typedef x a type refers

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: ion name, return Declaration: type, and precise argument list type, Declaration is optional 53 Functions in C++ x Syntax for implementation: <return type> <functionName> ([type1 arg1] [, type2 arg2])
 { [instructions] [instructions] } x Syntax for prototype declaration: <return type> <functionName> ([type1 arg1] [, type2 arg2])
; 54 Example int main()
 { return 0; return } double mysqrt(double x)
 { double return sqrt(x)
; return } 55 Return type x Can be any type previously declared int, float, double, const unsigned long int, … User-defined types x It implies there is a ‘return xxx’ statement in the It instructions, which can always be reached instructions, x Can be void: it is the special type stating that nothing is Can returned by the function returned void foo()
 { std::cout << “This is a void function!” << std::endl; std::cout } 56 Types and typedef x A type refers to a specific, well defined category of data type Known storage, known operations A variable (in C++)
 always has a type x Be careful: function arguments are typed too, but void is Be not an acceptable type for a variable! not x A useful feature: create an alias on a type typedef const unsigned int cuint_t; cuint_t myvariable = 42; cuint_t x Can create as many alias on the same type as we want 57 Another example typedef float number_t; number_t anumber; void setANumber(float x)
 { anumber = x / 2.0; anumber } int main()
 { i...
View Full Document

Ask a homework question - tutors are online