Exams:

MAKAUT BTech CSE

Answer:

A pointer is a variable that stores the address of some other variable, instead of data. An integer variable can store some integer value, but an integer type pointer variable can only hold the address of an integer variable. We can also access and change the value of the integer variable using the pointer.

Explanation

The “data” stored within a pointer variable is considered as an “address”.

“37, M. N. Sen Street, Kolkata 700001 ” – Is it an address or data?

When we see the above text on an envelope, the text is considered to be an address. But, if we see the same text on someone’s driving license or Adhar Card, the same text is considered to be data. Similarly, The data stored within a pointer variable is a Hexadecimal number which represents the address of some variable.

Example:

The following code snippet shows how to use a pointer.

int main(){
    int x;  // creating an integer
    int *p; // creating a pointer to integer variable
    x = 5;
    p = &x;
    printf("x contains %d at location %x", x , &x);
    printf("\n");
    printf("p contains %x at location %x", p , &p);
    printf("\nAccessing x via p:-\n");
    printf("value of x is %d", *p);
    return 0;
}
sample-output

Related Question:

  1. What is the address of any variable?
  2. Can a pointer variable store values?
  3. What type of values can be stored in a pointer variable?
  4. Can we perform addition or subtraction on pointers?
  5. What is the use of * while using pointers in C?

0 Replies to “What is a pointer variable in C?

  1. Simply want to say your article is as astonishing. The clarity in your post is just nice and i could assume you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the rewarding work.

    https://turkiserial.co/

Leave a Reply

Your email address will not be published. Required fields are marked *