小编use*_*766的帖子

结构指针?出了点问题

嗨,我正在尝试用结构中的指针创建一个程序.编译器似乎没有问题,但程序崩溃.请问你能帮帮我吗 ?

#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)

c struct pointers

1
推荐指数
2
解决办法
401
查看次数

内存中char指针的C字节

我想计算一个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个字节?

c pointers allocation

0
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×2

pointers ×2

allocation ×1

struct ×1