-
Notifications
You must be signed in to change notification settings - Fork 0
C_Memory_Address.c
ani9977 edited this page Sep 11, 2024
·
1 revision
Here's the updated code with comments and explanations:
#include <stdio.h> // Includes the standard input-output library for input-output functions
int main() { // Main function where the program execution starts
int number = 10; // Declares an integer variable 'number' and assigns the value 10 to it
// Prints the memory address of the 'number' variable using the %p format specifier for pointers
printf("Address of number: %p\n", &number); // &number retrieves the address of the variable 'number'
return 0; // Returns 0, indicating successful program execution
}-
int number = 10;: This declares an integer variablenumberand assigns it the value 10. -
printf("Address of number: %p\n", &number);: Theprintffunction prints the memory address of thenumbervariable.- The
&numberretrieves the memory address of the variablenumber. - The
%pformat specifier is used to print the address in pointer format (hexadecimal).
- The
-
return 0;: This statement indicates the program completed successfully and returns 0 to the operating system.
This program demonstrates how to use pointers in C by printing the memory address of an integer variable. In C, each variable is stored at a specific location in memory, and you can access that address using the & operator.