我错过了什么? [英] what I miss?
问题描述
#include< stdio.h>
#include< stdlib.h>
#include< limits.h>
>
int main()
{
unsigned char * c;
c = malloc(sizeof(unsigned char));
printf(" unsigned char的大小:%d \ n",sizeof(unsigned char));
printf(" c的大小:%d \ n",sizeof(c));
返回0;
}
执行此操作时,它表示大小unsigned char是1是1。 &安培;尺寸
的c是4。这不是很奇怪吗?
(gcc版本4.0.0 20050519(Red Hat 4.0.0-8))
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
unsigned char *c;
c = malloc(sizeof(unsigned char));
printf("size of unsigned char: %d\n", sizeof(unsigned char));
printf("size of c: %d\n", sizeof(c));
return 0;
}
When I execute this, it says that size of "unsigned char" is "1" & size
of "c" is "4". isn''t that strange?
( gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) )
推荐答案
Parahat Melayev < PA ***** @ gmail.com>在消息中写道
news:11 ********************** @ g47g2000cwa.googlegr oups.com ...
"Parahat Melayev" <pa*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
#include< stdio.h>
#include< stdlib.h>
#include< limits.h>
int main()
{
unsigned char * c;
c = malloc(sizeof(unsigned char));
printf(" unsigned char的大小:%d \ n",sizeof(unsigned) char));
printf(c:%d \ n的大小,sizeof(c));
返回0;
}
我执行此操作,它表示unsigned char的大小。是1是1。 &安培; c的大小
是4。这不奇怪吗?
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
unsigned char *c;
c = malloc(sizeof(unsigned char));
printf("size of unsigned char: %d\n", sizeof(unsigned char));
printf("size of c: %d\n", sizeof(c));
return 0;
}
When I execute this, it says that size of "unsigned char" is "1" & size
of "c" is "4". isn''t that strange?
不。 C不是char,它是指针(对于char)。
Alex
Nope. C isn''t a char, it''s a pointer (to a char).
Alex
哦是的,那是对:)恐慌
tnx
oh yeah that is right :) panic
tnx
Parahat Melayev写道:
Parahat Melayev wrote:
#include< stdio.h>
#include< stdlib.h>
#include< limits.h>
int main()
{
unsigned char * c;
c = malloc(sizeof(unsigned char));
printf(" unsigned char的大小:%d \ n",sizeof(unsigned char));
printf(c:%d \ n的大小,sizeof(c));
返回0;
} >
当我执行此操作时,它表示unsigned char的大小。是1是1。 &安培; c的大小
是4。这不奇怪吗?
什么是c ????
c是指针,它将保存
char的地址类型。
malloc将返回已分配内存的地址。
等等c保存地址,即int。
>
c = malloc(sizeof(unsigned char));
HTH
ranjeet
(gcc 4.0版。 0 20050519(Red Hat 4.0.0-8))
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
unsigned char *c;
c = malloc(sizeof(unsigned char));
printf("size of unsigned char: %d\n", sizeof(unsigned char));
printf("size of c: %d\n", sizeof(c));
return 0;
}
When I execute this, it says that size of "unsigned char" is "1" & size
of "c" is "4". isn''t that strange?
what is c ????
c is the pointer which is going to hold the address which is of the
char type.
malloc will return the address of the allocated memory.
and so c holds the address, which is int.
c = malloc(sizeof(unsigned char));
HTH
ranjeet
( gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) )
这篇关于我错过了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!