zoukankan      html  css  js  c++  java
  • 结构体与结构体指针

    下述代码在VS2010上的cpp文件可通过,在杭电OJ上的G++编译项上可通过。

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 struct student{
     4     student *p;
     5     int a;
     6     student()
     7     {
     8         a=100;
     9         p=NULL;
    10     }
    11 };
    12 int main()
    13 {
    14     student *root=new student();
    15     printf("%d
    ",root->a);
    16     printf("%s
    ",root->p);
    17     system("Pause");
    18     return 0;
    19 }

     改变值与改变指向的区别(包括赋值)

     1 #include<stdio.h>
     2 struct node{
     3     node *next;
     4     int num;
     5     node()
     6     {
     7         next=NULL;
     8     }
     9 };
    10 void insert(node *a,int x)
    11 {
    12     a->next=new node();
    13     a->next->num=x;
    14     return ;
    15 }
    16 int main()
    17 {
    18     node *a=new node();
    19     a->num=6;
    20     insert(a,10);
    21     node *p=a;
    22     insert(p,8);
    23     while(p!=NULL)
    24     {
    25         printf("%d",p->num);
    26         p=p->next;
    27         printf("
    ");
    28     }
    29     while(a!=NULL)
    30     {
    31         printf("%d",a->num);
    32         a=a->next;
    33                 printf("
    ");
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    使用webstorm来创建并且运行vue项目详细教程
    Jmeter后置处理器之Json提取器
    Linux常用命令
    Linux安装Mysql
    Linux安装JDK
    redhat6.5安装yum
    Linux安装python
    Linux安装Tomcat
    搞懂Redis协议RESP
    1TB是多大?
  • 原文地址:https://www.cnblogs.com/holyprince/p/3293523.html
Copyright © 2011-2022 走看看