小编C G*_*thy的帖子

(void*)和(void(*)(参数类型))cast之间有什么区别?

void funcPtr(int a);

int main(){
   int k=1;
   void (*funcPtr2)(int);

   funcPtr2 = (void*)(funcPtr);
   // funcPtr2 = (void(*)(int))(funcPtr);

   (*funcPtr2)(k);
   return 0;
}

void funcPtr(int a){
   printf("%d", a);
}
Run Code Online (Sandbox Code Playgroud)

(void*)(void(*)(argument type)函数指针类型转换有什么区别?

因此,它不会发生警告.

这是错的吗?关于(void*)型铸造

c c++ pointers

7
推荐指数
1
解决办法
1127
查看次数

将元素添加到链表(C)

我想创建一个链接列表,我可以在以后添加更多元素,但我对当前代码的问题是所有以前的元素被最后添加的元素覆盖.这是我的代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node {
    char *name;
    struct node *next;
}*head;



void add( char *str ) {
    struct node *temp;
    temp=(struct node *)malloc(sizeof(struct node));
    temp->name=str;

    if (head== NULL) {
        head=temp;
        head->next=NULL;

    } else {
        temp->next=head;
        head=temp;
    }
}

void  display(struct node *r) {
    r=head;
    if(r==NULL)
        return;

    while(r!=NULL) {
        printf("%s ",r->name);
        r=r->next;
    }

    printf("\n");
}

int  main()
{
    char *str;
    struct node *n;
    head=NULL;
    while(scanf("%s",str) == 1) {
        add(str);
        display(n);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c structure linked-list

0
推荐指数
1
解决办法
109
查看次数

标签 统计

c ×2

c++ ×1

linked-list ×1

pointers ×1

structure ×1