UrbanPro
true

Take BCA Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Pointers Concept

Sudarshan Gupta
07/06/2017 0 0

Every variable has a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory. Consider the following example, which prints the address of the variables defined:

int main () {   int  var1;   char var2[10];   printf("Address of var1 variable: %x\n", &var1  );   printf("Address of var2 variable: %x\n", &var2  );   return 0;}

Output:
Address of var1 variable: bff5a400Address of var2 variable: bff5a3f6

A pointer is a variable whose value is the address of another variable, i.e, direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address. The general form of a pointer variable declaration is:

type *var-name;

Here, type is the pointer's base type, it must be a valid C data type and var-name is the name of the pointer variable. The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer. Take a look at some of the valid pointer declarations:

int    *ip;    /* pointer to an integer */double *dp;    /* pointer to a double */float  *fp;    /* pointer to a float */char   *ch     /* pointer to a character */

#include int main () {   int  var = 20;   /* actual variable declaration */   int  *ip;        /* pointer variable declaration */   ip = &var;  /* store address of var in pointer variable*/   printf("Address of var variable: %x\n", &var  );   /* address stored in pointer variable */   printf("Address stored in ip variable: %x\n", ip );   /* access the value using the pointer */   printf("Value of *ip variable: %d\n", *ip );   return 0;}

Output:
Address of var variable:bffd8b3cAddress stored in ip variable:bffd8b3cValue of *ip variable:20
0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Data Structures
A data structure is a particular way of organizing data in a computer so that it can be used efficiently. Data structures can implement one or more particular Abstract Data Types (ADT), which specify...

Looking for BCA Tuition ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for BCA Tuition Classes?

The best tutors for BCA Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BCA Tuition with the Best Tutors

The best Tutors for BCA Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more