Skip to main content

Posts

Showing posts with the label pointers to arrays

Understanding pointers in C Part1 - Basics of Pointer

Pointers are one of the most difficult concepts in C language to grasp. Many programmers get confused in pointers.I am one of them. I decided to write series of blog posts covering basic to advance concepts of pointers. This is the first part to understand very basic of pointer that what pointer actually is and how we can store/access data through pointers. Put simply A pointer is a variable that contains the address of a variable Lets try to understand pointers using some code. int x=3; int *ptrToX; ptrToX=&x;  In above code we simply took a variable x of type int . Then we define a pointer ( * denotes that variable is a pointer and it is known as indirection or dereferencing operator ) ptrToX  of type int and assigned address of x to ptrToX . Now ptrToX points to x . Note that ptrToX do not contain value of x ( i.e 3 ) instead it contains memory address of x . Now we can access and manipulate value of x using ptrToX . Accessing value of a variable ...