嗨,我正在尝试用结构中的指针创建一个程序.编译器似乎没有问题,但程序崩溃.请问你能帮帮我吗 ?
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
int pos;
typedef struct _Parking Parking;
struct _Parking
{
int pos;
char name[15];
char description[80];
float price;
int slots[5];
char last_driver_id;
int reservations;
};
Parking *myaccounts;
int create_Parking()
{
strcpy(myaccounts->name,"Pro");
myaccounts->pos ++;
return pos-1;
}
int main()
{
int a;
a = create_Parking();
printf("a=%d\n",a);
printf("name=%s\n",myaccounts->name);
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想计算一个char指针占用内存的字节数.指针指向一个包含100个字符的字符串.
根据以下程序,char需要4个字节
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char b;
b = 'b';
printf("%p\n",&b);
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
指针是否相同?因此,对于100个字符串,它在内存中保存了400个字节?