POINTERS
Hey people in this blog you are going to read about “Pointers”.Well, we use pointers in C and C++. Why not Java or python?
Pointers reduce the data
security in python.
In java, no
pointer support make Java more secure because they point to memory
location that loses the security as we use them directly.
So we will first see pointers in C
Pointers in C
The
general form of pointer declaration is,
How to use
pointers?
1) 1. Declare a variable
2)
2. Declare a pointer variable
3)
3. Point the address of the variable to the pointer
variable
NULL pointer
concept
It is said that assigning the pointer variable to NULL
is a good practice in cases you don’t have an exact address.
Check out the output to understand it more clear.
Programs are not permitted to access memory at
address 0 because that memory is reserved by the operating system. But the
memory address 0 gesticulates that the pointer is not intended to point to an accessible
memory location.
A simple application of NULL pointer you can see here,
In this if pointer is NULL the pointer will have value as 0 and if the pointer is not NULL then it will have some non zero value. Here, "if()" will not work in first case and will work in the second one.
Pointers
in C++
C++ pointers are easy and fun to learn. Some C++
tasks are performed more easily with pointers, and other C++ tasks, like
dynamic memory allocation, cannot be performed without them.
Look at the code below and consider the output on
your own for better understanding.
The notation is same as of C,
type *var_name;
Using pointers
in C++
The procedure is same as of C.
Look the code below,
The concept of
NULL pointer in C++ is also the same as of C,
Note:- We
actually have just gave you a brief idea about pointers only. Pointers has many
other application which will be available soon.
If you still have any doubt on this topic then do come to us via email "sophomoretechs@gmail.com" or via instagram "@coding.winds".
We also have an article on space complexity and time complexity , do give them a read.
No comments:
Post a Comment