मैं संकेत के साथ कुछ समझने की कोशिश कर रहा था, इसलिए मैं इस कोड लिखा है: जब जीसीसी के साथ संकलनमुद्रण संकेत
#include <stdio.h>
int main(void)
{
char s[] = "asd";
char **p = &s;
printf("The value of s is: %p\n", s);
printf("The direction of s is: %p\n", &s);
printf("The value of p is: %p\n", p);
printf("The direction of p is: %p\n", &p);
printf("The direction of s[0] is: %p\n", &s[0]);
printf("The direction of s[1] is: %p\n", &s[1]);
printf("The direction of s[2] is: %p\n", &s[2]);
return 0;
}
मैं इन चेतावनियों मिलती है:
$ gcc main.c -o main-bin -ansi -pedantic -Wall -lm
main.c: In function ‘main’:
main.c:6: warning: initialization from incompatible pointer type
main.c:9: warning: format ‘%p’ expects type ‘void *’, but argument 2 has type ‘char (*)[4]’
main.c:11: warning: format ‘%p’ expects type ‘void *’, but argument 2 has type ‘char **’
main.c:12: warning: format ‘%p’ expects type ‘void *’, but argument 2 has type ‘char ***’
(झंडे के लिए जीसीसी हैं क्योंकि मुझे सी 8 9 होना चाहिए)
सूचक के असंगत प्रकार क्यों? किसी सरणी का नाम उसके पहले तत्व के लिए सूचक नहीं है? तो यदि एस 'ए' के लिए सूचक है, &s
char **
होना चाहिए, नहीं? और मुझे अन्य चेतावनियां क्यों मिलती हैं? क्या उन्हें मुद्रित करने के लिए पॉइंटर्स (void *
) के साथ डालना है?
और जब मैं कुछ इस तरह मिल चलाने:
$ ./main-bin
The value of s is: 0xbfb7c860
The direction of s is: 0xbfb7c860
The value of p is: 0xbfb7c860
The direction of p is: 0xbfb7c85c
The direction of s[0] is: 0xbfb7c860
The direction of s[1] is: 0xbfb7c861
The direction of s[2] is: 0xbfb7c862
कैसे कर सकता है रों के मूल्य और यह दिशा (और निश्चित रूप से p
का मूल्य) एक ही हो सकता है?
आपको बहुत धन्यवाद जेम्स ... – alcuadrado
एक सरणी का अर्थ है कि एक सूचक के लिए 's' decays के बाद से विशेष प्रकार का एक संगत स्मृति पता, हम कह सकते हैं कि यह 'char *' [सरणी का पहला तत्व] –
@ CholthiPaulTtiopic - नहीं सबसे पहले, यह होना चाहिए "हम कह सकते हैं कि यह 'char'' ('char *' नहीं) के लिए एक सूचक है। लेकिन, आप इसे कुछ मामलों में 'char' के सूचक के रूप में उपयोग कर सकते हैं, लेकिन यह इसे एक नहीं बनाता है। "5.0" एक पूर्णांक हो सकता है, लेकिन यह 'int' नहीं है, हालांकि आप इसे कुछ स्थानों पर उपयोग कर सकते हैं जो' int 'लेते हैं। –