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

相关文章

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

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

C和指针:字符串

字符串、字符和字节 字符串基础 字符串就是一串零个或多个字符,并且以一个位模式为全0的NUL字节结尾。 字符串长度就是字符串中字符数。 size_t strlen( char const *string ); string为指针常量(const修饰string),指向的string是常量不能修改。size_t是无符号数,定义在stddef.h。 #include <stddef.h>

PHP7扩展开发之数组处理

前言 这次,我们将演示如何在PHP扩展中如何对数组进行处理。要实现的PHP代码如下: <?phpfunction array_concat ($arr, $prefix) {foreach($arr as $key => $val) {if (isset($prefix[$key]) && is_string($val) && is_string($prefix[$key])) {$arr[