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: Abhi

Hi, this is Abhilash - Senior Programmer Analyst at CoMakeIT, specialised on web programming. Mainly working on Ruby On Rails platform since 2010.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s