typedef,后加指针,数组等

2024-05-04 05:18
文章标签 数组 指针 typedef 后加

本文主要是介绍typedef,后加指针,数组等,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

很简单,定义一个指针。它的类型和struct相关。如果typedef后面有多个定义,我们可以逐个拆开。

    typedef int *PInt, Int, **PPInt;
我们可以拆成:
//    typedef int *PInt;
//    typedef int **PPInt;
//    typedef int Int;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>void test_typedef_p();
void test_typedef_normal();int main(int argc, char *argv[])
{test_typedef_p();test_typedef_normal();return 0;
}void test_typedef_normal(){typedef int *PInt, Int, **PPInt;//    typedef int *PInt;
//    typedef int **PPInt;
//    typedef int Int;Int a=1;PInt pint_a = &a;PPInt ppint_a=&pint_a;printf("ppinta:= %d \n", **ppint_a);
}void test_typedef_p(){
#if 0struct node {int data;struct node *next;} *head =NULL;
#elsetypedef struct node {int data;struct node *next;}   *NodePtr, Node, *NodePer2;Node  *head =NULL;
#endifhead =(struct node*)malloc(sizeof(struct node));memset(head, 0, sizeof(struct node));head->data=1;head->next=NULL;printf(" head data is: %d \n ", head->data);    NodePtr pointer_str;pointer_str =(struct node*)malloc(sizeof(struct node));memset(pointer_str, 0, sizeof(struct node));pointer_str->data=1;pointer_str->next=NULL;printf("pointer_str data is: %d \n ", pointer_str->data);NodePtr pointer_str2;pointer_str2 =(Node*)malloc(sizeof(Node));memset(pointer_str2, 0, sizeof(Node));pointer_str2->data=1;pointer_str2->next=NULL;printf("pointer_str2 data is: %d \n ", pointer_str2->data);//        const NodePtr p3;
//        p3 = pointer_str2;const NodePtr p3 = pointer_str2;//p3 =(Node*)malloc(sizeof(Node));memset(p3, 0, sizeof(Node));p3->data=2;p3->next=NULL;printf("p3 data is: %d \n ", p3->data);}

typedef 后还可以跟数组:

typedef int IntArramy[10];

IntArray array;

这篇关于typedef,后加指针,数组等的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/958404

相关文章

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

JAVA中整型数组、字符串数组、整型数和字符串 的创建与转换的方法

《JAVA中整型数组、字符串数组、整型数和字符串的创建与转换的方法》本文介绍了Java中字符串、字符数组和整型数组的创建方法,以及它们之间的转换方法,还详细讲解了字符串中的一些常用方法,如index... 目录一、字符串、字符数组和整型数组的创建1、字符串的创建方法1.1 通过引用字符数组来创建字符串1.2

vue如何监听对象或者数组某个属性的变化详解

《vue如何监听对象或者数组某个属性的变化详解》这篇文章主要给大家介绍了关于vue如何监听对象或者数组某个属性的变化,在Vue.js中可以通过watch监听属性变化并动态修改其他属性的值,watch通... 目录前言用watch监听深度监听使用计算属性watch和计算属性的区别在vue 3中使用watchE

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while

【C++学习笔记 20】C++中的智能指针

智能指针的功能 在上一篇笔记提到了在栈和堆上创建变量的区别,使用new关键字创建变量时,需要搭配delete关键字销毁变量。而智能指针的作用就是调用new分配内存时,不必自己去调用delete,甚至不用调用new。 智能指针实际上就是对原始指针的包装。 unique_ptr 最简单的智能指针,是一种作用域指针,意思是当指针超出该作用域时,会自动调用delete。它名为unique的原因是这个

C语言:柔性数组

数组定义 柔性数组 err int arr[0] = {0}; // ERROR 柔性数组 // 常见struct Test{int len;char arr[1024];} // 柔性数组struct Test{int len;char arr[0];}struct Test *t;t = malloc(sizeof(Test) + 11);strcpy(t->arr,

C语言指针入门 《C语言非常道》

C语言指针入门 《C语言非常道》 作为一个程序员,我接触 C 语言有十年了。有的朋友让我推荐 C 语言的参考书,我不敢乱推荐,尤其是国内作者写的书,往往七拼八凑,漏洞百出。 但是,李忠老师的《C语言非常道》值得一读。对了,李老师有个官网,网址是: 李忠老师官网 最棒的是,有配套的教学视频,可以试看。 试看点这里 接下来言归正传,讲解指针。以下内容很多都参考了李忠老师的《C语言非

C 语言基础之数组

文章目录 什么是数组数组变量的声明多维数组 什么是数组 数组,顾名思义,就是一组数。 假如班上有 30 个同学,让你编程统计每个人的分数,求最高分、最低分、平均分等。如果不知道数组,你只能这样写代码: int ZhangSan_score = 95;int LiSi_score = 90;......int LiuDong_score = 100;int Zhou

计算数组的斜率,偏移,R2

模拟Excel中的R2的计算。         public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)         {             bool bResult = true;             int n = 0;             dou