惭愧了 这么久才又开始学习
abstration
defination
Design that hides the details of how something works while still allowing the user to access complex functionality
what is an abstraction
Key idea:Through a simpler interface, users are able to take full advantage of a complex system without needing to know how it works or how it was made.
includes
angle bracket
use of the angle bracket operators is usually reserved for code from the C++ Standard library
quote
use of the quotes is usually reserved for code from the Stanford C++ libraries, or code in files that you have written yourself
variables and types
variables
A way for code to store information by associating a value with a name
we will think of a variable as a named container storing a value
types
All variables have a type associated with them, where the type describes the representation of the variable.
In C++,all types must be explicitly defined when the variable is created, and a variable cannot change its type.
funtion
anatomy of a function
definition:
parameter(s):
one or more variables that your function expects as input.
argument(s):
the values passed into your function and assigned to its parameter variables.
return value:
the value that your function hands back to the "calling" function.
returnType functionName(varType parameter1, varType parameter2, ...){
returnType variable = /* Some fancy code */
/* more code */
return variable;
}
Pass-by-value is the default mode of operation when it comes to parameters in C++,which means that parameter is passed to function by value,variable is a copy of the variable passed in,changing it inside the function does not change the value in the calling function.
循环什么的不想记(瘫
string
- Strings are mutable in C++
- You can add characters to strings and strings to strings using += and +
- Strings must use double quotes(““)while characters use single(‘’)
- You can use logical operators to compare strings(and characters)(only comparing the first letter)
when running
string hiThere = "hi"+"there";
you would get a error
cause there are cpp string and c string in cpp,when declare a string like “hi” you would get a c string,which is not allowed to be added together.
when running
string hiThere = "hi"+'!';
you would get a garbage
cause when add a different type to a c string, it would point to random garbage.
C strings vs C++ strings summary
- C strings have no methods
- This is why you can’t do something like “hi”.length() in C++
- Conversion fixes
- Store the C string in a variable first to convert it to a C++ string
- Use a conversion function
- string(“text”); // converts the C string literal into a C++ string
- strig.c_str(); // return a C string from a C++ string
Takeaway:Beware of C string