arrays and user defined function basics

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

array

special variable having one name, but storing a list of data items, with each item being directly accessible. Some languages use a construct similar to an array called a vector. Each item in an array is known as an element

  • each element’s location number is called the index

2
New cards

array syntax

an array variable is an ordered list of items of a given data type and size. Each iteem in an array is called an element. For array x, each element is accessed as x[0], x[1]… In an array access, the number in brackets is called the index of that element

  • array indices start with 0 rather than 1

3
New cards

array summary

  • An array variable stores multiple items, each accessible using an index. In contrast, a scalar variable stores just one item.

  • Array indices start from 0, not 1. An index may be represented as an expression.

4
New cards

basics of functions

  • a function is a named list of statements

  • a function definition consists of the new function’s name and a block of statements. The function’s name can be any valid identifier

  • a function call is an invocation of a function’s name, causing the function’s statements to execute

  • a local variable is a variable declared in a function, which is then accessible only within that function

5
New cards

parameters

  • a programmer can influence a function’s behavior via an input

  • an argument is a value provided to a function’s parameter during a function call

  • a parameter is like a variable declaration. Upon a call, the parameter’s memory location is allocated, and the parameter is assigned with the argument’s value. Upon return, the parameter is deleted from memory

6
New cards

returning a value from a function

a function may return one value by assigning a return variable with the return value

7
New cards

modular and incremental program development

programmers commonly use functions to write programs modularly and incrementally

  • modular development is the process of dividing a program into separate modules that can be developed and tested separately and then integrated into a single program

  • incremental development is a process in which a programmer writes and tests a few statements, then writes and tests a small amount more (an incremental amount), and so on

  • a function stub is a function definition whose statements have not been written yet

  • a programmer can use function stubs to capture the hgih level behavior rof the main function and the required functions before diving into the details of each function

8
New cards

function definition

in coral this begins with the word Function, the function’s name, and a list of comma-separated parameters in parentheses and a return indication. The parentheses are required even if no parameters exist. The function’s slocal variables and statements start on the next line and are indented

9
New cards

function call

consists of the function name and parentheses, within which comma-separated arguments appear. A program’s execution starts by calling the Main() function, which may itself call other functions

10
New cards

functions summary

  • A function is a named list of statements.

  • A function definition consists of the new function's name and a block of statements. The function's name can be any valid identifier.

  • A function call is an invocation of a function's name, causing the function's statements to execute.

  • A program's execution begins with the Main function.

  • A programmer can influence a function's behavior via an input. A parameter is a function input specified in a function definition. An argument is a value provided to a function's parameter during a function call.

  • A parameter is like a variable declaration. Upon a call, the parameter's memory location is allocated, and the parameter is assigned with the argument's value.

  • A function may return one value by assigning a return variable with the return value.

  • A function call evaluates to the returned value. Thus, a function call often appears within an expression.

  • Decomposing a program into functions can greatly aid program readability, helping yield an initially correct program, and easing future maintenance.

  • Programmers commonly use functions to write programs modularly and incrementally.

  • Modular development is the process of dividing a program into separate modules that can be developed and tested separately and then integrated into a single program.

  • Incremental development is a process in which a programmer writes and tests a few statements, then writes and tests a small amount more (an incremental amount), and so on.

  • A function can be defined once, then called from multiple places in a program, thus avoiding redundant statements.

  • The skill of decomposing a program's behavior into a good set of functions is a fundamental part of programming that helps characterize a good programmer.

  • Each function should have easily-recognizable behavior, and the behavior of the Main function (and any function that calls other functions) should be easily understandable via the sequence of function calls.

  • A function's statements may include branches, loops, calls to other functions, and other statements.