# Session 8

## | Pointers Session 8 Objectives Explain what a pointer is and where it is used Explain how to use pointer variables and pointer operators Assign values to pointers Explain pointer arithmetic Explain pointer comparisons Explain pointers and single dimensional arrays Explain Pointer and multidimensional arrays Explain how allocation of memory takes place What is a Pointer? A pointer is a variable, which contains the address of a memory location of another variable If one variable contains the address of another variable, the first variable is said to point to the second variable A pointer provides an indirect method of accessing the value of a data item Pointers can point to variables of other fundamental data types like int, char, or double or data aggregates like arrays or structures What are Pointers used for? Some situations where pointers can be used are - To return more than one value from a function To pass arrays and strings more conveniently from one function to another To manipulate arrays easily by moving pointers to them instead of moving the arrays itself To allocate memory and access it (Direct Memory Allocation) Pointer Variables A pointer declaration consists of a base type and a variable name preceded by an * General declaration syntax is : For Example: type *name; int *var2; Pointer Operators There are 2 special operators which are used with pointers : The & operator is a unary operator and it returns the memory address of the operand The second operator * is the complement of &. It is a unary operator and returns the value contained in the memory location pointed to by the pointer variable’s value and & * var2 = &var1; temp = *var2; Assigning Values To Pointers-1 Values can be assigned to pointers through the & operator. Here the address of var is stored in the variable ptr_var It is also possible to assign values to pointers through another pointer variable pointing to a data item of the same data type ptr_var = &var; ptr_var = &var; ptr_var2 = . | Pointers Session 8 Objectives Explain what a pointer is and where it is used Explain how to use pointer variables and pointer operators Assign values to pointers Explain pointer arithmetic Explain pointer comparisons Explain pointers and single dimensional arrays Explain Pointer and multidimensional arrays Explain how allocation of memory takes place What is a Pointer? A pointer is a variable, which contains the address of a memory location of another variable If one variable contains the address of another variable, the first variable is said to point to the second variable A pointer provides an indirect method of accessing the value of a data item Pointers can point to variables of other fundamental data types like int, char, or double or data aggregates like arrays or structures What are Pointers used for? Some situations where pointers can be used are - To return more than one value from a function To pass arrays and strings more conveniently from one function to another To .

TÀI LIỆU LIÊN QUAN
32    57    1
25    199    2
7    63    0
55    301    6
23    153    0
23    97    0
7    45    0
41    75    12
17    31    2
9    482    32
TÀI LIỆU XEM NHIỀU
13    40835    2412
3    24927    248
25    24432    4276
16    20041    2845
20    19483    1543
14    19263    2967
1    19245    615
37    16149    2958
3    15949    329
1    14554    132
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
5    80    2    23-05-2024
21    1    1    23-05-2024
3    70    2    23-05-2024
115    73    4    23-05-2024
58    80    2    23-05-2024
17    77    1    23-05-2024
11    250    1    23-05-2024
8    256    2    23-05-2024
139    77    1    23-05-2024
11    47    1    23-05-2024
10    500    2    23-05-2024
23    243    1    23-05-2024
6    79    1    23-05-2024
5    134    4    23-05-2024
12    78    2    23-05-2024
136    248    4    23-05-2024
140    76    1    23-05-2024
111    73    4    23-05-2024
5    66    1    23-05-2024
9    7    1    23-05-2024
TÀI LIỆU HOT
3    24927    248
13    40835    2412
3    2764    81
580    5083    363
584    3337    100
62    6659    1
171    5695    719
2    3124    78
51    4452    200
53    4726    188
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.