I have a few questions. This is not homework. I just want to understand better.
So, if I have
int * b = &k;
Then it kshould be an integer, but it bis a pointer to a position kin memory, right?
k
b
What is the main "data type" b? When I output it, it returns things like 0x22fe4c, which I assume is hexadecimal for the memory position 2293324, right?
0x22fe4c
2293324
Where exactly is the memory position "2293324"? "Heap"? How can I display the values of, for example, in memory positions 0, 1, 2and so on?
0
1
2
If I deduce *b, this is the same as the output kdirectly, because it *somehow means the value that it points to b. But it looks different than the announcement bthat was announced int * b = k, so if it *means “value”, then it doesn’t mean “declare bvalue k? It’s not, but I still want to understand what it means, the language is wise.
*b
*
int * b = k
If I post &b, it actually returns the address of the pointer itself and has nothing to do with k, right?
&b
I can also do int & a = k;that that seems to match int a = k;. As a rule, there is no need to use &this way?
int & a = k;
int a = k;
&
1- .
2 " ". int. . "int" "char" c/++.
3 , . . b-- ( "b" "int" . , , int.)
4- * . . =. , == , =. .
5- & b - b. k, b k. , (** (& b)), , , b. k. , .
6- int & a = k a k. a , , k. a = 1, k 1. .
int & a = k
a
, . .
:
, b - pointer k: k , k.
pointer
" " b - int: , , , b int, b: b - .
int
: , , , , .
* de-reference b. , b - , *b - , at b. k, *b k.
, &b - , k b.
int & a = k k, , k. , , , .
void addThree(int& a) { a += 3; } int main() { int a = 3; //'a' has a value of 3 addThree(a); //adds three to 'a' a += 2; //'a' now has a value of 8 return 0; }
addThree a, , int a main() .
addThree
int a
main()
void addThree(int* a) { //Takes a pointer to an integer *a += 3; //Adds 3 to the int found at the pointer address } int main() { int a = 3; //'a' has a value of 3 addThree(&a); //Passes the address of 'a' to the addThree function a += 2; //'a' now has a value of 8 return 0; }
, :
void addThree(int a) { a += 3; //A new variable 'a' now a has value of 6. } int main() { int a = 3; //'a' has a value of 3 addThree(a); //'a' still has a value of 3: The function won't change it a += 2; //a now has a value of 5 return 0; }
. * . & (lvalue) . . , . , .
3 - k - , . k - , . , b. , , malloc(), calloc(),.... , alloca() ( _alloca()) (alloca() ).
An example with an array:
int array_of_5_integers[5]; int *ptr_to_int; int (*ptr_to_array_of_5_integers)[5]; ptr_to_int = array_of_5_integers; ptr_to_array_of_5_integers = &array_of_5_integers;
Source: https://habr.com/ru/post/1621741/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1621736/extraction-part-of-image-that-matches-to-a-mask-in-opencv&usg=ALkJrhhRaXvYY-fg4bgEe8i-KoOeuMyIPwSearch for records with the same and different fields - c #RangeError: call stack size error in JS function - javascriptIs Spring Batch ItemWriter a singleton class? - javaProblems releasing GIFs for Android - androidQuestions about classes extending from a base class (Java) - javaФайлы заголовков не найдены GCC - gccT-SQL table and other variables in one DECLARE block - syntaxMySQL utf8mb4 на Amazon RDS: глобальные переменные заданы правильно, но переменные не установлены - mysqlEspresso Test for Notification of Appearance - androidAll Articles