Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

C Memory Address

Memory Address

In C, when a variable is declared, it is assigned a memory address, which indicates where the variable is stored in the computer’s memory. When a value is assigned to the variable, it is stored at this memory address.

To access this address, the reference operator (&) is used, and the resulting value represents the location of the variable in memory.

Example

int myAge = 43;
printf(“%p”, &myAge); // Outputs 0x7ffe5367e044

Please note that the memory address is typically represented in hexadecimal form (0x..). The result you obtain in your program may differ, as it depends on the specific location where the variable is stored in your computer’s memory.

It’s worth mentioning that &myAge is commonly referred to as a “pointer.” Essentially, a pointer stores the memory address of a variable as its value. To print pointer values, we utilize the %p format specifier.

In the upcoming chapter, you’ll delve deeper into pointers and gain a more comprehensive understanding of their usage.

Why is it useful to know the memory address?

Pointers play a crucial role in C programming by enabling manipulation of data stored in the computer’s memory, leading to streamlined code and enhanced performance.

They distinguish C from other languages such as Python and Java.