Is the study of pointers in C is easy?

Here explains a little about pointers.  Yes the pointers are easy, of course. But take care in your building path. If you go through pointers deeply, you will see the complexity.

In C address is only for l-values. It can be a variable or something. If we assign p = &a, the type of p is int * – pointer to an integer. type of ‘a’ is int and type of ‘&a’ is int *. C language is a weakly typed language. ie when we use assignment,  C allows to assign the right most thing to the left most without checking the types of these two.

int *p;
p = 1;
*p = 10;
Consider the above statements in C. We declared p as a pointer variable. Then 1 is assigned to p. In the third statement 10 is assigning to the memory location 1. What about the memory location 1, is there exists a memory address 1. Usually not. If yes, of course it isn’t accessible. OS allows the program to access only within a particular memory location. This is Memory protection. If OS takes no care about memory protection what happens? In that system so many programs are running and two programs want to store data on say 2000 th location then what happens? The programs access wrong data.

int *p;
p = 0;
*p = 10;

By executing above statements there is no error at compile time. Why? C takes zero as a pointer.

Its easy to go further.

Author: Abhilash

Hey! This is Abhilash - A Ruby developer, specialised on web development. I am also working on other frameworks such as Angular, Sinatra, Laravel, NodeJS etc. Ruby On Rails is my primary software framework, which I do since 2010. This blog is about Ruby, Ruby On Rails and other subjects that I have had experienced upon. You can contact me here: abhilash.amballur@gmail.com LinkedIn: www.linkedin.com/in/abhilashak

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: