Help shape GoConqr. What should we add next?

Flashcards

COMP 206 Unit 3: The C in C++

Adriana Vincelli-Joma COMP 206 University-level C++ English 88 cards

Cards in this deck (88)

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

Information

Description
COMP 206 at Athabasca University
Views
47
Tags
c++computer programmingathabasca universityathabascacomp 206
Rating

More on Conditionals and Loops

Feedback

What is it about?

What should we add next?