Flashcards
COMP 206 Unit 3: The C in C++
Flashcards do conjunto (88)
- 1function prototypeuses description of types of arguments when declaring/defining function
- 2Components of function prototype- name
- input parameters (parentheses)
- type of return value (or void) - 3voidspecifies that no value is returned
- 4return- returns value from function
- exits function back to point right after function - 5Purpose of C Librarysomeone already solved your problem and gave it more thought and debugging
- 6Using C Function Library- find programming reference
- description of function demonstrates syntax of code
- has at least one #include line, showing you header file containing function prototype
- duplicate #include line in file so function is properly declared - 7librarianmanages groups of object modules
- 85 Execution Control Statements- if-else
- while
- do-while
- for
- switch - 9if-elseif(expression)
statement
else
statement
- if condition is true, first statement is executed; if it is false, second statement is executed - 10whilewhile(expression)
statement
- statement repeats until controlling expression evaluates to false - 11do-whiledo
statement
while(expression);
- statement always executes at least once, even if expression evaluates to false first time - 12forfor(initialization; conditional; step)
statement
-allows you to execute block of code specified number of times - 13initializationcode executes once at very beginning
- 14conditionaltested before each iteration
- 15stepexecutes at end of each loop
- 16breakquits loop without executing rest of statements in loop
- 17continuestops execution of current iteration and goes back to beginning of loop to begin new iteration
- 18while(true)do loop forever
- 19switchstatement selects from among pieces of code based on value of integral expression
switch(selector) {
case integral-value 1 : statement; break;
case integral-value 2 : statement; break;
(...)
default: statement;
} - 20goto- statement used to jump from anywhere to anywhere within a function
- makes it difficult to trace control of flow of program - 21recursionprogramming technique whereby you call function you're in
- function calls itself directly/indirectly - 22Basic Operatorsaddition: +
subtraction/unary minus: -
multiplication: *
division: /
assignment: =
modulus: % ; remainder from division - 23precedencedefines order in which expression evaluates when several different operators are present
- 24auto-decrement operator-- ; decrease by one unit
- 25auto-increment operator++ : increase by one unit
- 26++Aoperation first performed and resulting value is produced
- 27A++current value is produced, and then operator is performed
- 28Basic Data Types- char
- int
- float
- double - 29charcharacter storage and uses minimum of 8 bits
- 30intstores integral number and uses minimum of two bytes of storage
- 31floatsingle-precision floating point; 4 bytes
- 32doubledouble-precision floating point; 8 bytes
- 33booltwo states expressed by the built-in constants true (converts to integral one) and false (converts to integral zero)
- 34longmodify max value data type will hold
- 35shortmodify min value data type will hold
- 36signedrepresent both positive and negative values
- 37unsignedinteger can never be negative
- 38pointertype of variable that holds an address
- 39dereferenceaccess or manipulate data contained in memory location pointed to by a pointer; *
- 40addresslocation of object in memory; &
- 41referencealternative name for an existing variable
- 42pass by valuepass arguments to function, copy of argument is made inside function
- 43pass by referenceparameter becomes alias for argument; argument and parameter refer to same area of storage
- 44Purpose of Pointerhold address and use address to modify original value
- 45Pointer vs Reference- pointers store address of variable
- references refer to existing variable in another name - 46scopingtells you where variable is valid, where it is created, and where it gets destroyed
- 47"goes out of scope"where variable gets destroyed
- 48on the flyallows you to define variables anywhere in scope, so you can define variable right before you use it
- 49global variabledefined outside all function bodies and are available to all parts of program
- 50local variableoccur within scope; automatically come into being when scope is entered and automatically go away when scope closes
- 51registermake access to variable as fast as possible
- 52static- value is extant throughout life of program
- initialization is performed only first time function is called
- unavailable outside scope of function, so it can't be inadvertently changed - 53externtells compiler that variable/function exists, even if compiler hasn't yet seen it in file currently being compiled
- 54constrepresents constant
- 55volatileprevents compiler from performing any optimizations based on stability of variable
- 56const vs volatile- const variable cannot be changed
- volatile can change at any time - 57static vs volatile- static variable initialization is performed only first time function is called, data retains its value between function calls
-volatile variable always read whenever value is required, even if it was just read line before - 58Relational Operatorsless than: <
greater than: >
less than/equal to: <=
greater than/equal to: >=
equivalent: ==
not equivalent: != - 59Logical Operatorstrue: non-zero value
false: zero value
and: &&
or: || - 60Bitwise Operatorsmanipulate individual bits in number
and: &; produces one in output bit if both input bits are 1; otherwise produces 0
or: |; produces one in output bit if either input bit is 1; produces 0 if both input bits are 0
xor: ^; produces 1 in output bit if one or other input bit is 1, but not both
not: ~; only takes one argument; ones complement operator
nor: opposite of input bit; 1 if input is 0; 0 if input is 1 - 61Shift Operatorsleft-shift operator: <<; produces operand to left of operator shifted to left by number of bits specified after operator
right-shift operator: >>; produces operand to left of operator shifted to right by number of bits specified after operator - 62Unary Operatorslogical not: !; takes true value and produces false value
unary minus: - ; produces negative of value
unary plus: + ; provides symmetry with unary minus
address-of (&) and dereference (* and ->): used with pointers - 63ternary operatorif-else:
- three operands
- a = --b ? b : (b = -99) - 64comma operator- separate variable names in multiple definitions
- used in function argument lists
- used as operator to separate expression - 65castchanges one type of data into another
- 66static_const- typical castless conversions
- narrowing conversions
-forcing conversion from void*
-implicit type conversions
-static navigation of class hierarchies - 67const_castconvert from const to nonconst or from volatile to nonvolatile
- 68reinterpret_castpretends object is bit pattern that can be treated as if it were an entirely different type of object
- 69sizeofgives info about amount of memory allocated for data items
- 70asmescape mechanism that allows you to write assembly code for your hardware within C++ program
- 71aliasingsituation where two different expressions or symbols refer to same object
- 72typedefcreate alias that can be used anywhere in place of type name
- 73structcollects groups of variables into structure
- 74enumautomatically enumerates any list of identifiers you give it by assigning them values of 0, 1, 2, etc.
- 75unionpiles all data into single space
- 76array-clumps variables together, one right after the other, under single identifier name
-set of consecutive memory locations used to store data - 77array identifierhook into square-bracket syntax; read-only pointer to beginning of array
- 78pointer arithmetic- cannot add two pointers
-if you subtract pointers, result is number of elements between two pointers
- can add/subtract integral value and pointer - 79preprocessor debugging flag#define: defines one or more debugging flags
#ifdef: test flags
#undef: removes code - 80assert()convenient debugging macro; in standard header file
- 81NDEBUGflag used to to change way code is generated by macros
- 82function pointervariable that stores address of function; allows you to pass and store functions to variables
- 83separate compilationbreaking code into number of translation units
- 84makeutility that allows programmer to manage compilation and linking of separate program units (source files) and libraries
- 85makefiletext file that contains instructions for make; description of how to compile program
- 86macrosallow convenient string replacement; invoke C++ compiler
- 87targetfile that you want rebuilt
- 88Use of Macros- = : used to identify macro
- $ and () : expand macro
Informações
- Descrição
- COMP 206 at Athabasca University
- Criado por
- Adriana Vincelli-Joma
- Visualizações
- 47
- Tags
- Avaliação
Mais sobre Conditionals and Loops