CMPSC 16 Lecture Notes - Lecture 4: Global Variable, Type System, Local Variable

23 views2 pages
School
Course
Professor

Document Summary

To reduce the amount of code that is used over and over. 3 steps to a function: define, declare, call. Syntax for functions: returnvalue functionname(parameters); //declares the function. Definition is when the code is actually written for the function in between { } Can call the function when it is only declared. If the function is not declared before main, then it cannot be used (error) The function can be declared before main and then initialized after main and it will work. For now, declare functions before main and initialize them after main. There would be a compile-time error since it is a type mismatch. The function sum_2() has a return type of void, and the variable it is trying to be stored in has a type of integer. Local variable: variable declared inside a function that can only be used inside the function. Global variable: variables that are outside of the functions and can be used anywhere.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions