Midterms Flashcards
group of statements that together perform a task
function
tells the compiler about a function’s name, return type, and parameters
function
already present inside the header file, included at the beginning of a program
library functions
we have tow write a body of a function and call the function when required
user-defined functions
why we need functions in c++
- errors are easy to track
- reduces size of code
-replacing duplicate statements with function calls - reusability of code
- improves code readability
various forms of the main method
main()
main (void)
void main()
void main (void)
int main (int argc, charargv[])
void main(int argc, charargv[])
main method that does not return any value should have the return type?
void
main method that returns a value should have the return type?
int
also called function prototype. specifies the name of a function to be used in the program like a variable declaration
function declaration
syntax of function declaration
return_data_type function_name (data type arguments);
means writing the body of a function, consisting of statements that perform specific tasks
function definition
invoking a function also means
calling a function/function call
two methods to call a function
- call by value
- call by reference
copies the actual value of an argument into the formal parameter of the function
call by value
function that is expanded in line when it is invoked thus saving time
inline function
Makes program execution faster because it saves the function location into the compile time
Inline function
this is accessible by all the private and protected members of the class
friend function
true or false: a friend function cannot be called using the object of the class as it is not in the scope of the class
true
declares members that are not bound to class instances; shared by all objects of the class
static data members
why return 0?
- represents the status of the program
- a zero value indicates that the program is successful and a non-zero value indicates a problem in the program
- the program execution will reach the return zero statement if the above statements executed successfully
describe int main
int main is a declaration defining the main function. it returns an integer value to the operating system. the return value can be used to indicate the success or failure of the program (with 0 typically indicating success), which can be useful for debugging code.
what is a main function?
main functions are the entry point of any program or the function that is called when the program is first launched.
what is void main ()
void main() is a declaration of the main function that doesn’t return any value to the operating system. it is used when one doesn’t want to return any value to the main function. however, this is not the standard main method for programming; it is not recommended for use.
what is int main (int argc, char**argv)?
this is also a main method that returns an integer value but takes two parameters: argc and argv. this is used for command-line prompting. the argc parameter represents the number of command-line arguments passed to the program, including the name of the program itself. meanwhile, argv, is an array of character pointers representing the actual command-line arguments.
which main methods are standard-compliant?
int main() and int main (int argc, char argv[])
void main is not
this is the ability to take more than one form
polymorphism
this allows objects to have different internal structure to share the same external interface
polymorphism
the number and type of arguments that a function may take is defined in the function itself
function overloading
true or false: a function may take zero or more arguments when called
treu
this is the function without its body
prototype of a function
this declares the return type of the function that declares the number, the types and order of parameters the function expects to receive
function prototype