C का Memory Address
In this page:
&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?
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Address-of Operator &
& operator, जिसे address-of operator कहते हैं, किसी variable के नाम से ठीक पहले रखा जाता है उसकी current value की बजाय उस variable का memory address retrieve करने के लिए।
उदाहरण: The Address-of Operator &
// 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;
}
Login to try C/C++/Java/PHP code in the editor
एक Address Print करना
%p format specifier specifically memory addresses दिखाने के लिए printf के साथ इस्तेमाल होता है, और address को print करने से पहले conventionally (void*) में cast किया जाता है।
उदाहरण: Printing an Address
// 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;
}
Login to try C/C++/Java/PHP code in the editor
हर Variable का एक Address है
C program में हर variable का एक memory address है, individual array elements, struct instances, और यहाँ तक कि function parameters समेत, क्योंकि हर एक storage का एक distinct piece represent करता है।
उदाहरण: Every Variable Has an Address
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Addresses और Pointers
एक pointer specifically एक memory address store करने के लिए design किया गया एक variable है, और यह समझना कि एक address क्या है और & इसे कैसे retrieve करता है, यह समझने की essential foundation है कि pointers कैसे काम करते हैं।
उदाहरण: Addresses and Pointers
// 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;
}
Login to try C/C++/Java/PHP code in the editor
- एक address को
%pकी बजाय%dसे print करना, जो 64-bit systems पर गलत है। &x(x का address) कोx(इसकी value) से confuse करना।- यह मान लेना कि एक address हर run पर same रहता है, जब यह बदल सकता है।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: