一些指针问题.... [英] some pointer issues....

查看:61
本文介绍了一些指针问题....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double * X [5]


尺寸X-> ??

尺寸X [0] - > ??


double(* X)[5]

尺寸X-> ??

尺寸X [0] - > ; ??

此外,如果我想打印sizeof(主要)它给我1

和sizeof(main())给我4个为什么?

double * X[5]

size of X->??
size of X[0]->??

double (*X)[5]
size of X->??
size of X[0]->??
Also if i want to print sizeof(main) it gives me 1
and sizeof(main()) gives me 4 why?

推荐答案

8月12日17:24,sumedh ..... < sumedhsak ... @ gmail.comwrote:
On 12 Aug., 17:24, "sumedh....." <sumedhsak...@gmail.comwrote:

double * X [5]


X-> ; ??

大小为X [0] - > ??


double(* X)[5]

尺寸X-> ?? ??

尺寸为X [0] - > ??


另外如果我想打印sizeof(主要)它给我1

和sizeof(main())给我4个为什么?
double * X[5]

size of X->??
size of X[0]->??

double (*X)[5]
size of X->??
size of X[0]->??

Also if i want to print sizeof(main) it gives me 1
and sizeof(main()) gives me 4 why?



试试这个测试程序:


/ **************** ************ /

#include< stdio.h>


double * X [5];

/ * X是一个包含5个双指针的数组。 * /


double(* Y)[5];

/ * Y是指向5个双打数组的指针* /


int main(无效)

{

double array_of_5_double [] = {0.5,1.5,2.5,3.5,4.5};

X [0] =& array_of_5_double [0];

X [1] =& array_of_5_double [1];

X [2] =& ; array_of_5_double [2];

X [3] =& array_of_5_double [3];

X [4] =& array_of_5_double [4];

#if 0 //为什么这不起作用?

X = {& array_of_5_double [0],/ * array_of_5_double * / \

& array_of_5_double [1],\

& array_of_5_double [2],\

& array_of_5_double [3],\

& ; array_of_5_double [4]};

#endif

printf(" sizeof(double)=%d // sizeof(double *)=%d //

sizeof(double(*)[5])=%d \ n",\

sizeof(double),sizeof(double *),sizeof(double(*) )[5]));

/ * 8 * /


printf(" size) (X)=%d // X =%p \ n",sizeof(X),X,

& array_of_5_double);


printf(" sizeof(X [0])=%d // X [0] =%p //& array_of_5_double [0]

=%p \ n",sizeof(X [0]),X [0],& array_of_5_double [0]);

// X [0]是我们数组的第一个元素:这里是指向

双倍价值0.5

printf(sizeof(Y)=%d \ n,sizeof(Y));

printf(" sizeof(Y [0])=%d \ n",sizeof(Y [0])); // 40

printf(" sizeof(main)=%d // sizeof(main())=%d \ n",sizeof(main),
sizeof(main()));


返回0;

}


/ *

main是一个函数指针!

main()是函数int main(void)的调用。这将是
返回以下大小的整数:

sizeof(int)== sizeof(main())

* /


说明:


double * X [5];

/ * X是一个包含5个指针的数组加倍 * /

因此sizeof(X)= 5 * sizeof(double *)

" double *"是指向double的指针(提示:从右向左移动)

double(* Y)[5];

/ * Y是指向数组的指针5个双打* /

因此sizeof(Y)= sizeof(double(*)[5])

" double(*)[5]"是一个指向5个双打数组的指针(提示:从

里面移到外面)

/ *

/ *

main是一个函数指针!

main()是函数int main(void)的调用。这将是
返回以下大小的整数:

sizeof(int)

这个sizeof(main())大小相同,即返回的大小

整数

* /


-anon.asdf

Try this test program:

/****************************/
#include <stdio.h>

double *X[5];
/* X is an array of 5 "pointers to double" */

double (*Y)[5];
/* Y is a pointer to an array of 5 doubles */

int main(void)
{
double array_of_5_double[] = {0.5, 1.5, 2.5, 3.5, 4.5};
X[0] = &array_of_5_double[0];
X[1] = &array_of_5_double[1];
X[2] = &array_of_5_double[2];
X[3] = &array_of_5_double[3];
X[4] = &array_of_5_double[4];
#if 0 // why does this not work?
X = {&array_of_5_double[0], /* array_of_5_double */ \
&array_of_5_double[1], \
&array_of_5_double[2], \
&array_of_5_double[3], \
&array_of_5_double[4]};
#endif
printf("sizeof(double) = %d // sizeof(double *) = %d //
sizeof(double (*)[5]) = %d\n", \
sizeof(double), sizeof(double *), sizeof(double (*)[5]));
/* 8 */

printf("sizeof(X) = %d // X = %p\n", sizeof(X), X,
&array_of_5_double);

printf("sizeof(X[0]) = %d // X[0] = %p // &array_of_5_double[0]
= %p\n", sizeof(X[0]), X[0], &array_of_5_double[0]);
// X[0] is the first element of our array: here it is a pointer to a
double with value 0.5

printf("sizeof(Y) = %d\n", sizeof(Y));

printf("sizeof(Y[0]) = %d\n", sizeof(Y[0])); // 40

printf("sizeof(main) = %d // sizeof(main()) = %d\n", sizeof(main),
sizeof(main()));

return 0;
}

/*
main is a function pointer!
main() is the invocation of the function "int main(void)" which will
return an integer of the following size:
sizeof(int) == sizeof(main())
*/

Explanations:

double *X[5];
/* X is an array of 5 "pointers to double" */
Thus sizeof(X) = 5*sizeof(double *)
"double *" is a pointer to a double (tip: move from right to left)
double (*Y)[5];
/* Y is a pointer to an array of 5 doubles */
Thus sizeof(Y) = sizeof(double (*)[5])
"double (*)[5]" is a pointer to an array of 5 doubles (tip: move from
inside to outside)
/*
/*
main is a function pointer!
main() is the invocation of the function "int main(void)" which will
return an integer of the following size:
sizeof(int)
This sizeof(main()) is the same size, i.e. the size of the returned
integer
*/

-anon.asdf


8月12日9:21 pm,anon.a ... @ gmail.com写道:
On Aug 12, 9:21 pm, anon.a...@gmail.com wrote:

8月12日。,17:24,sumedh ..... < sumedhsak ... @ gmail.comwrote:
On 12 Aug., 17:24, "sumedh....." <sumedhsak...@gmail.comwrote:

double * X [5]
double * X[5]


大小X-> ?? ??

大小X [0] - > ??
size of X->??
size of X[0]->??


double(* X)[5]

尺寸X-> ??

大小的X [0] - > ??
double (*X)[5]
size of X->??
size of X[0]->??


此外,如果我想打印sizeof(main)它给我1

和sizeof(main())给出我4为什么?
Also if i want to print sizeof(main) it gives me 1
and sizeof(main()) gives me 4 why?



试试这个测试程序:


/ **************** ************ /

#include< stdio.h>


double * X [5];

/ * X是一个包含5个双指针的数组。 * /


double(* Y)[5];

/ * Y是指向5个双打数组的指针* /


int main(无效)

{

double array_of_5_double [] = {0.5,1.5,2.5,3.5,4.5};

X [0] =& array_of_5_double [0];

X [1] =& array_of_5_double [1];

X [2] =& ; array_of_5_double [2];

X [3] =& array_of_5_double [3];

X [4] =& array_of_5_double [4];

#if 0 //为什么这不起作用?

X = {& array_of_5_double [0],/ * array_of_5_double * / \

& array_of_5_double [1],\

& array_of_5_double [2],\

& array_of_5_double [3],\

& ; array_of_5_double [4]};

#endif

printf(" sizeof(double)=%d // sizeof(double *)=%d //

sizeof(double(*)[5])=%d \ n",\

sizeof(double),sizeof(double *),sizeof(double(*) )[5])); <无线电通信/>
/ * 8 * /


printf(" sizeof(X)=%d // X =%p \ n" ;, sizeof(X), X,

& array_of_5_double);


printf(" sizeof(X [0])=%d // X [0] =%p //& array_of_5_double [0]

=%p \ n",sizeof(X [0]),X [0],& array_of_5_double [0]);

// X [0]是我们数组的第一个元素:这里是一个指向

double的指针,值为0.5



printf(" sizeof(Y [0])=%d \ n" ,sizeof(Y [0])); // 40

printf(" sizeof(main)=%d // sizeof(main())=%d \ n",sizeof(main),
sizeof(main()));


返回0;


}


/ *

main是一个函数指针!

main()是函数int main(void)的调用。这将是
返回以下大小的整数:

sizeof(int)== sizeof(main())

* /


说明:


double * X [5];

/ * X是一个包含5个指针的数组加倍 * /

因此sizeof(X)= 5 * sizeof(double *)

" double *"是指向双精度的指针(提示:从右向左移动)


double(* Y)[5];

/ * Y是指针到5个双打的数组* /

因此sizeof(Y)= sizeof(double(*)[5])

" double(*)[5]" ;是一个指向5个双打数组的指针(提示:从

里面移到外面)

/ *


/ *

main是一个函数指针!

main()是函数int main(void)的调用。这将是
返回以下大小的整数:

sizeof(int)

这个sizeof(main())大小相同,即返回的大小

整数

* /


-anon.asdf


Try this test program:

/****************************/
#include <stdio.h>

double *X[5];
/* X is an array of 5 "pointers to double" */

double (*Y)[5];
/* Y is a pointer to an array of 5 doubles */

int main(void)
{
double array_of_5_double[] = {0.5, 1.5, 2.5, 3.5, 4.5};
X[0] = &array_of_5_double[0];
X[1] = &array_of_5_double[1];
X[2] = &array_of_5_double[2];
X[3] = &array_of_5_double[3];
X[4] = &array_of_5_double[4];
#if 0 // why does this not work?
X = {&array_of_5_double[0], /* array_of_5_double */ \
&array_of_5_double[1], \
&array_of_5_double[2], \
&array_of_5_double[3], \
&array_of_5_double[4]};
#endif
printf("sizeof(double) = %d // sizeof(double *) = %d //
sizeof(double (*)[5]) = %d\n", \
sizeof(double), sizeof(double *), sizeof(double (*)[5]));
/* 8 */

printf("sizeof(X) = %d // X = %p\n", sizeof(X), X,
&array_of_5_double);

printf("sizeof(X[0]) = %d // X[0] = %p // &array_of_5_double[0]
= %p\n", sizeof(X[0]), X[0], &array_of_5_double[0]);
// X[0] is the first element of our array: here it is a pointer to a
double with value 0.5

printf("sizeof(Y) = %d\n", sizeof(Y));

printf("sizeof(Y[0]) = %d\n", sizeof(Y[0])); // 40

printf("sizeof(main) = %d // sizeof(main()) = %d\n", sizeof(main),
sizeof(main()));

return 0;

}

/*
main is a function pointer!
main() is the invocation of the function "int main(void)" which will
return an integer of the following size:
sizeof(int) == sizeof(main())
*/

Explanations:

double *X[5];
/* X is an array of 5 "pointers to double" */
Thus sizeof(X) = 5*sizeof(double *)
"double *" is a pointer to a double (tip: move from right to left)

double (*Y)[5];
/* Y is a pointer to an array of 5 doubles */
Thus sizeof(Y) = sizeof(double (*)[5])
"double (*)[5]" is a pointer to an array of 5 doubles (tip: move from
inside to outside)
/*

/*
main is a function pointer!
main() is the invocation of the function "int main(void)" which will
return an integer of the following size:
sizeof(int)
This sizeof(main()) is the same size, i.e. the size of the returned
integer
*/

-anon.asdf



gr8说明:

只是想知道为什么

sizeof(主要)-1

sizeof(main( ))-sizeof(int)?????

gr8 explanation:
just wanted to know why does
sizeof(main) -1
sizeof(main()) -sizeof(int)?????




" sumedh ....." < su ********** @ gmail.comwrote in message

news:11 ******************** *@i13g2000prf.googlegro ups.com ...

"sumedh....." <su**********@gmail.comwrote in message
news:11*********************@i13g2000prf.googlegro ups.com...

double * X [5]
double * X[5]



Array类型为double的五个指针

Array of five pointers to type double


>

大小X-> ??
>
size of X->??



大小为X报告


sizeof X





sizeof(double * [5])


我推荐第一种方法。

size of X is reported by

sizeof X

or

sizeof(double *[5])

I recommend the first method.


大小为X [0] - > ??
size of X[0]->??



X [0]的大小报告由


sizeof X [0]





sizeof(双倍)


再次,我推荐第一种方法。

size of X[0] is reported by

sizeof X[0]

or

sizeof(double)

Again, I recommend the first method.


>

double(* X)[5]
>
double (*X)[5]



指向五个双精度数组的指针/>

Pointer to an array of five doubles


X->的大小?
size of X->??



大小为X报告


sizeof X





sizeof(double(*)[5]


再次,我推荐第一种方法。

size of X is reported by

sizeof X

or

sizeof(double(*)[5]

Again, I recommend the first method.


大小X [0] - > ??
size of X[0]->??



大小X [0]报告


sizeof X [0]




sizeof(double [5])


再次,我推荐第一种方法。

size of X[0] is reported by

sizeof X[0]

or

sizeof(double[5])

Again, I recommend the first method.


>


另外如果我想打印sizeof(main )它给了我1

和sizeof(main())给了我4个为什么?
>

Also if i want to print sizeof(main) it gives me 1
and sizeof(main()) gives me 4 why?



''main''(没有括号)产生函数''main()''的地址为

。因此sizeof(main)将给出函数指针大小

。''main( )''调用

函数main(),并返回它的返回值。这个

类型''int''。


请注意,这些类型的大小会因平台而异(并且
$ b $对于相同的

平台,b可能会有所不同。


-Mike

''main'' (without parentheses) yields the address of
the function ''main()''. So sizeof(main) will give
the size of a pointer to a function. ''main()'' invokes
the function main(), and returns its return value. This
type is ''int''. So ''sizeof(main())'' gives the size of
type ''int''.

Note that these type sizes will vary among platforms (and
could conceivably vary among implementations for the same
platform).

-Mike


这篇关于一些指针问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆