在“指向结构的指针”中的查询 [英] A Query in "Pointers to Structures"
问题描述
大家好。我有一个问题。让我们说下面给出: -
struct struct1 {
char * word;
int n;
} * p;
QUERIES:
以下内容是什么?
1)p-> ;字
2)(* p) - > n
3)(* p) - >字
4)*( p->字)
Hello everyone. I have a query. Lets say that following is given:-
struct struct1{
char *word;
int n;
} *p;
QUERIES:
What does the following refer to?
1) p->word
2) (*p)->n
3) (*p)->word
4) *(p->word)
推荐答案
" dbz" < pu ************** @ gmail.comwrote in message
news:11 **************** ******@75g2000cwc.googlegro ups.com ...
"dbz" <pu**************@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
大家好。我有一个问题。让我们说下面给出: -
struct struct1 {
char * word;
int n;
} * p;
QUERIES:
以下内容是什么?
1 )p->字
2)(* p) - > n
3)(* p) - >字
4)*(p-> word)
Hello everyone. I have a query. Lets say that following is given:-
struct struct1{
char *word;
int n;
} *p;
QUERIES:
What does the following refer to?
1) p->word
2) (*p)->n
3) (*p)->word
4) *(p->word)
1)p-> word ==(* p).word == char数组的第一个元素的地址。
2)因为p,这将是非法间接的。不是双指针,但是如果它是
(* p) - > n ==(*(* p))。n ==数字存储变量n。
3) - 2)== char数组的第一个元素的地址。
4)char的第一个元素数组。
1) p->word == (*p).word == adress of first element of char array.
2) That would be illegal indirection since "p" is not a double pointer, but
if it is than
(*p)->n == (*(*p)).n == number stored in variable n.
3) --2) == adress of first element of char array.
4) First element of char array.
dbz写道:
dbz wrote:
大家好。我有一个问题。让我们说下面给出: -
struct struct1 {
char * word;
int n;
} * p;
QUERIES:
以下是什么?
Hello everyone. I have a query. Lets say that following is given:-
struct struct1{
char *word;
int n;
} *p;
QUERIES:
What does the following refer to?
家庭作业。
Homework.
1)p-> word
2 )(* p) - > n
3)(* p) - >字
4)*(p->字)
1) p->word
2) (*p)->n
3) (*p)->word
4) *(p->word)
August
August
dbz写道:
dbz wrote:
大家好。我有一个问题。让我们说下面给出: -
struct struct1 {
char * word;
int n;
} * p;
QUERIES:
以下内容是什么?
1 )p->字
2)(* p) - > n
3)(* p) - >字
4)*(p->字)
Hello everyone. I have a query. Lets say that following is given:-
struct struct1{
char *word;
int n;
} *p;
QUERIES:
What does the following refer to?
1) p->word
2) (*p)->n
3) (*p)->word
4) *(p->word)
还没有。你已经声明了一个结构并定义了一个指向它的指针,
但是你还没有结构。
p = malloc(sizeof * p) ;
现在,假设malloc成功,p指向一个结构,p [0]是
结构。
1. p->单词很好。
2. p-> n或(* p).n或p [0] .n
3.(* p).word或p [0] .word
4. *(p-> word)就好了。
-
Joe Wright
所有东西都应尽可能简单,但不能简单。
--- Albert爱因斯坦---
Nothing yet. You have declared a structure and defined a pointer to it,
but you don''t have a structure yet.
p = malloc(sizeof *p);
Now, assuming success of malloc, p points to a structure and p[0] is the
structure.
1. p->word is just fine.
2. p->n or (*p).n or p[0].n
3. (*p).word or p[0].word
4. *(p->word) is just fine.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
这篇关于在“指向结构的指针”中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!