Remember Me
forgot your password?

Effetive Use of Pointers

Abstact :

     This article shows an impotance of pointers. pointer is nothing but variables which can hold address. pointer variable need memory address as its value. we can't stotre direct value in pointer variables. Understanding pointer has  litle confusion to beginers but there's no real magic to pointers, and a lot of readers will already be familiar with their use. The only peculiarity of C is how heavily it relies on the use of pointers, compared with other languages, and the relatively permissive view of what you can do with them.

 

Declaring pointers

Pointer is a variable so  just like other variables, you have to declare pointers before you can use them. Pointer declarations look much like other declarations: but don't be misled. When pointers are declared, the keyword at the beginning (c int, char and so on) declares the type of variable that the pointer will point to. The pointer itself is not of that type, it is of type pointer to that type. A given pointer only points to one particular type, not to all possible types. Here's the declaration of an array and a pointer:

  example:

      int *p, *name, *ptr;

      int x, *pt;    // Declare with other variables also.

Once pointer has been declared we must initialize pointer variable before use.

      p = &x;

     pt= name;  //  name is array variable of type char

                     //  all array variable name can directly assign to pointer variables

Example for array : int ar[5], *ip; ip = &ar[3];

In that example, the pointer is made to point to the member of the array ar whose index is 3, i.e. the fourth member. This is important. You can assign values to pointers just like ordinary variables; the difference is simply in what the value means. The values of the variables that we have now are shown in Figure  (?? means uninitialized).

      ar[0]    ar[1]   ar[2]

the avove three array variables can have continious memory locations.  these variables can initialized indiviualy or by single statement like this.

     ar[0] = &x;    ar[1]= &y;  ar[2]=&z;

      or

   ptr=ar;    // normal initializtion

 

   Example program.

#include
#include
main(){
      int x, *p;

      p = &x;         /* initialise pointer */
      *p = 0;         /* set x to zero */
      printf("x is %dn", x);
      printf("*p is %dn", *p);

      *p += 1;        /* increment what p points to */
      printf("x is %dn", x);

      (*p)++;         /* increment what p points to */
      printf("x is %dn", x);

      exit(EXIT_SUCCESS);
}

 

 

varadarajan t

pointers in c - yashwant kanitkar
programming in c - E balagurusamy
sprit of c - Mullish , Hopper

Rate this Article: 0 / 5 stars - 0 vote(s)
Print Email Re-Publish


Article Source: http://www.articlesbase.com/programming-articles/effetive-use-of-pointers-580449.html
Add new Comment



Captcha

  • Latest Programming Articles
  • More from varadarajan t

php software development company

By: usha sharma | 08/07/2009
Professional Web Development Company phpmaestro provides custom website development web application development ecommerce website design and development services. Custom web application development services and professional website development at affordable rates from phpmaestro Company. www.phpmaestro.com is a php Application Development Shopping Cart for e-commerce stores. Our shopping cart software gives our client full control over your online shop its products design development prices sh

Hire ASP .Net Developers Hire Dedicated ASP.Net Developers Offshore ASP.Net Programmers

By: Arshad | 08/07/2009
Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.

Windbg Minidump Tutorial:Setting up & Reading Minidump Files

By: Jeannie Lee | 07/07/2009
Windgb Minidump tutorial to set up and read minidump files (.dmp). Setting Symbol File Path. Output of Windbg command. windbg.exe -z [file path to minidump file.dmp] -c !analyze -v.

Javascript Validate Name Field

By: Jeannie Lee | 07/07/2009
Simple Javascript tutorial on validating a name field. Checks to see if there is a value in the name field with Javascript after the user submits a form.

Logo Design- The image creator!

By: Jhonny Sharma | 07/07/2009
Brand image is something that many consumers look for while buying a product. Brand image and brand positioning have become important concepts in the corporate world. When image building strategies are talked about, what tops the list is a creative logo design.

Design principles in logo

By: Jhonny Sharma | 07/07/2009
An element of balance is a mandatory aspect of design. A design is considered to be a great design when it incorporates all design aspects in the required proportion. The design principles are vital for any kind of design.

Organization specific software

By: Manish Shrivastava | 07/07/2009
Different businesses have different technological needs depending upon the type of work they are engaged in. Some businesses might require minimum use of software technology where there might be others whose very business might depend upon the optimum use of technology.

Hire .Net Developers: Hire ASP.Net Programmers

By: Arshad | 07/07/2009
Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.

Effetive Use of Pointers

By: varadarajan t | 27/09/2008 | Programming
pointers in c are one of the most striking features of c language. it has several advantages. it can save memory space effectively. using pointers we can handle array of data effectively. this article shows a basic idea of pointers and it usage.

Submit Your Articles Free: Signup


Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.23, 1)