← Back to C Course | Chapter 7: Pointers | Lesson 1 of 9

C का Memory Address

हर variable एक specific memory address पर रहता है, & operator से retrieve किया जाता है और %p से print किया जाता है, और addresses समझना pointers समझने की essential foundation है।
Syntax
c
&variable_name;  // address of the variable

printf("%p", (void*)&variable_name);

Memory Address क्या है?

एक चलते program में data का हर piece computer की memory में कहीं न कहीं store होता है, और वह specific location इसका memory address कहलाता है, एक number जो uniquely identify करता है कि एक value physically कहाँ रहती है।

उदाहरण: What is a Memory Address?

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	// Print formatted text to the screen
	printf("%p", (void*)&x);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Address-of Operator &

& operator, जिसे address-of operator कहते हैं, किसी variable के नाम से ठीक पहले रखा जाता है उसकी current value की बजाय उस variable का memory address retrieve करने के लिए।

उदाहरण: The Address-of Operator &

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare count and set it to 10
	int count = 10;
	// Print formatted text to the screen
	printf("%p", (void*)&count);
	// Return 0 to signal that the program finished successfully
	return 0;
}

एक Address Print करना

%p format specifier specifically memory addresses दिखाने के लिए printf के साथ इस्तेमाल होता है, और address को print करने से पहले conventionally (void*) में cast किया जाता है।

उदाहरण: Printing an Address

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	// Print formatted text to the screen
	printf("%p", (void*)&x);
	// Return 0 to signal that the program finished successfully
	return 0;
}

हर Variable का एक Address है

C program में हर variable का एक memory address है, individual array elements, struct instances, और यहाँ तक कि function parameters समेत, क्योंकि हर एक storage का एक distinct piece represent करता है।

उदाहरण: Every Variable Has an Address

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	int arr[3] = {1, 2, 3};
	// Print formatted text to the screen
	printf("%p", (void*)&arr[0]);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Addresses और Pointers

एक pointer specifically एक memory address store करने के लिए design किया गया एक variable है, और यह समझना कि एक address क्या है और & इसे कैसे retrieve करता है, यह समझने की essential foundation है कि pointers कैसे काम करते हैं।

उदाहरण: Addresses and Pointers

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	int *ptr = &x;
	// Print formatted text to the screen
	printf("%d", *ptr);
	// Return 0 to signal that the program finished successfully
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक address को %p की बजाय %d से print करना, जो 64-bit systems पर गलत है।
  2. &x (x का address) को x (इसकी value) से confuse करना।
  3. यह मान लेना कि एक address हर run पर same रहता है, जब यह बदल सकता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.