Skip to main content

Posts

Showing posts with the label The Crazy Programmer How to Print Address in C How to Print Address in C The Crazy Programmer

How to Print Address in C Nitish Agarwal The Crazy Programmer

In this article, we will first look at how can we assign an address to a variable and then print the address using C language. First of all, we will take a look at how addresses are assigned to any variable. Whenever we declare a variable of any data type (int, float, double, char, etc.), some memory is allocated to the variable by the operating system which can be any random number but cannot be negative. This random number is called the address of that variable and every variable has a unique address. To understand this concept in a more simple manner, let us take one real-life example. Suppose Rahul is a student of some university and lives in Hostel B, Room Number 32. Now, if someone asks me – Who lives in 32B? My prompt would be Rahul. Here, 32B is the address of a value named Rahul. Similar to this nature, addresses are assigned to variables in computer programs too. There exist two methods to print the address of a variable in C : Using address of (&), also called as