C) Programming Paradigms Flashcards
What are some data types?
- Boolean: true or false
- character: a single item e.g. a letter or a number
- float: a decimal number
- integer: a whole number
- string: one or more characters
Why are constants useful?
They protect from the value being accidentally changed and they can make a program easier to read and maintain.
What is the difference between declaring and defining a variable?
Declaring a variable is creating it, whereas defining a variable is setting/changing it.
Why is it important to give variables meaningful names?
- more readable
- easier to maintain
- easier to debug
What are some common naming conventions?
- camelCase
- snake_case
- PascalCase
What is a reserved word?
A set of words that cannot be used as identifiers, including instructions of the programming language.
What is the difference between local and global variables?
These are known as the scope of a variable, which refers to what parts of the program can access the data stored by the variable. Global variables are accessible throughout the entire code, whereas local variables are only accessible within the function they are declared in.
Why is it better to use local variables in a function rather than global?
They are more efficient as they only take up memory when the subprogram is running. They also increase code security as the values can only be accessed and altered within specific sections of the code.
What are the standard arithmetic operators?
- adds one value to another
- subtracts one value from another
- / divides one value by another
- multiplies one value by another
- % returns the remainder of dividing one value by another
- DIV (integer division) divides one value by another, ignoring any remainder
What is a relational operator and what are the standard relational operators.
They allow us to compare values and return either true or false.
- == returns true if both values are the same
- != returns true if both values are not the same
- = sets the value of a variable
- > returns true if a value is greater than another
- < returns true if a value is less than another
- >= returns true if a value is greater than or equal to another
- <= returns true if a value is less than or equal to another
What is a logical operator and what are the standard logical operators?
Allow multiple relational operators to eb combined for more complex expression.
- AND returns true if both conditions together are true
- OR returns true if either condition (or both) is true
- NOT returns true if the condition is false and vise versa
What is a function?
A named section of code that performs a set task when called. they are used to make code more readable, maintainable and reusable.
What is a library and what are their advantages/disadvantages?
A collection of predefined code that can be used in programs.
adv:
- saves time
- code in libraries have been extensively tested
disadv:
- you are relying on code someone else has produced
What are some common built-in arithmetic functions?
- random number generation
- generating a range of numbers
- rounding numeric values
What are some common built-in string handling functions?
- returning the length of a string
- extracting characters from a string
- returning substrings
- concatenation (joins two or more strings together)
- conversion (strings to arithmetic values)
- truncation (trims a string to a specified length)
What are some common built-in general purpose functions?
- input/output
- file handling