How to access the address of a variable without pointers?

How to access the address of a variable without pointers?

This is the example of c-programming. You can edit and compile code in your own way on clicking button. If you have better solution or you found any error on code, then give us suggestion.

Full Code:


Code Explanation :


Within this program we have an int type variable number. Number value is 10 and that value must be stored in memory somewhere, right? For each variable holding the value of that variable, a memory space is allocated; this memory space has an address. We live in a house for example, and our house has an address that helps us locate our home. The same is true for the variable value

So let's assume the address assigned to the variable num is 0x7fff5694dc58, which means that at the location 0x7fff5694dc58 should be stored any value we can assign to the number.

We will also see the access the address of a variable with pointers in this example.

Example of Pointer demonstrating the use of & and *

#include <stdio.h>
int main()
{
   /* Pointer of integer type, this can hold the
    * address of a integer type variable.
    */
   int *p;

   int var = 10;

   /* Assigning the address of variable var to the pointer
    * p. The p can hold the address of var because var is
    * an integer type variable.
    */
   p= &var;

   printf("Value of variable var is: %d", var);
   printf("nValue of variable var is: %d", *p);
   printf("nAddress of variable var is: %p", &var);
   printf("nAddress of variable var is: %p", p);
   printf("nAddress of pointer p is: %p", &p);
   return 0;
}

the output of above program will be :

Value of variable var is: 10
Value of variable var is: 10
Address of variable var is: 0x7fff5ed98c4c
Address of variable var is: 0x7fff5ed98c4c
Address of pointer p is: 0x7fff5ed98c50

These address may be different in your case because while compiling the code, program take may take different location on your computer/PC.

In this case, P is a pointer that store the address of variable var.

The data type of a pointer p and variable var should be match because all the integer pointer can only hold the address of integer value.

I hope, This program may help your to know about pointer. If you got any difficulty on understanding this example, then comment below. We will give your better explanation.



Our example mainly covers following topics in any programing

  • Basic Programs
  • Number Programs
  • Array Programs
  • Matrix Programs
  • Pattern Programs
  • String Programs
  • Tree Programs
  • Singly Linked List Programs
  • Circular Linked List Programs
  • Doubly Linked List Programs

Here we share programs on various topics such as array strings, series area & volume of geometric figures, mathematical calculation algorithms for sorting & searching and much more.Our goal is to provide you with the perfect solution to all the programming problems you may have encountered either during interviews or in class assignments. If you don’t find what you are looking for then please drop a line in the comment section of example page or you can request from account page so that we can get it added to the below collection of programs. Happy Learning!!


If you are confident with the above programs and are able to successfully understand and run them without any problems then it is time for you to take a step further and learn comprehensive programming principles using examples and flow diagrams. Here is the link: Programming tutorial lists .


If you find this example helpful, don't forget to share it with your friends. And stay updated with us by subscribing adzetech.


If you find any code error or grammetical error then you can suggest for example improvement on clicking below button.

Leave comment

Comments (1)

// SEARCH

What are you searching for....?

// SUBSCRIBE

Subscribe us on youtube to get our videos updates firstly on youtube.

// SUBSCRIBE

To receive updates on the latest news, tutorials and special offers, subscribe to our email newsletter today!

// CATEGORIES

x
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Privacy Policy That's Fine