当前位置:网站首页>First understanding of structure
First understanding of structure
2022-07-28 18:29:00 【51CTO】
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
// Initial structure
//struct stu //struct- Structure keywords stu- Structural tag struct stu- Type of structure
//{
// char name[20];
// short age;
// char tele[12];
// char sex[5];
//}s1,s2,s3;//s1,s2,s3- Global structure variables
//int main()
//{
// struct stu s;//s- Local structure variables
// return 0;
//}
//
//typedef struct stu//typedef- Rename this type
//{
// char name[20];
// short age;
// char tele[12];
// char sex[5];
//}stu;// The name for stu
//int main()
//{
// stu s1 = { " Zhang San ",20,"15866998877"," male " };
// struct stu s2 = { " Li Si ",25,"18957568899"," A secret " };
// return 0;
//}
//struct S
//{
// int a;
// char c;
// char arr[20];
// double d;
//};
//struct T
//{
// char ch[10];
// struct S s;
// char* pc;
//};
//int main()
//{
// char arr[] = "hello world\n";
// struct T t = { "hehe",{100,"w","hello hello",3.15}, arr};
// printf("%s\n", t.ch);//hehe
// printf("%s\n",t.s.arr);//hello hello
// printf("%lf\n", t.s.d);//3.15
// printf("%s\n", t.pc);//hello world
// return 0;
//}
// When structures transmit parameters , To transfer the address of the structure .
//typedef struct stu
//{
// char name[20];
// short age;
// char tele[12];
// char sex[5];
//}stu;
//void Print1(stu tmp)
//{
// printf("name:%s\n", tmp.name);
// printf("age :%d\n", tmp.age);
// printf("tele:%s\n", tmp.tele);
// printf("sex :%s\n", tmp.sex);
//}
//void Print2(stu* tmp)// This method is preferred
// // When a function passes parameters , Parameters need to be stacked , If you pass a structure object ,
// // The structure is too large , The system overhead of parameter stack pressing is relatively large , So it can lead to performance degradation .
//{
// printf("name:%s\n", tmp->name);
// printf("age :%d\n", tmp->age);
// printf("tele:%s\n", tmp->tele);
// printf("sex :%s\n", tmp->sex);
//}
//int main()
//{
// stu s = { " Li Si ",20,"15588886677"," male " };
// Print1(s);
// Print2(&s);
// return 0;
//}
// The stack area ---- local variable , The formal parameter of the function , The space opened up by function calls
// Heap area ---- Dynamic memory allocation (malloc,free,realloc,calloc)
// Static zone -- Global variables , Static variables
// data structure --{【 Linear data structure -- The order sheet , Linked list , Stack , queue 】,【 Tree data structure -- Binary tree , chart 】}
// Stack : First in, then out , Last in, first out . Pressing stack -- Insert an element Out of the stack -- Delete an element
//#include<stdlib.h>
//int main()
//{
// int i = 0;
// for (i = 0; i < 100; i++)
// {
// printf("%d ", i);
// }
// system("pause");// System commands - Pause
// return 0;
//}
// Realize it by yourself strcpy- String copy
//void my_strcpy(char* dest, char* src)// low-level
//{
// while (*src != '\0')// Copy the preceding characters
// {
// *dest = *src;
// src++;
// dest++;
// }
// *dest = *src;// Copy \0
//}
//
//void my_strcpy(char* dest, char* src)// primary
//{
// while (*dest++ = *src++)// hold src Copy the string to dest Point to space , contain \0 character .
// {
// ;
// }
//}
//
//void my_strcpy(char* dest, char* src)// intermediate
//{
// if (dest != NULL && src != NULL)// Determine the valid address , Invalid no execution
// {
// while (*dest++ = *src++)
// {
// ;
// }
// }
//}
//
//#include<assert.h>
//void my_strcpy(char* dest, char* src)// senior
//{
// assert(dest != NULL);// Assertion -- Address invalid error
// assert(src != NULL);// Assertion
// while (*dest++ = *src++)// hold src Copy the string to dest Point to space , contain \0 character .
// {
// ;
// }
//}
//int main()
//{
// char arr1[] = "*********";
// char arr2[] = "hello";
// my_strcpy(arr1, arr2);
// printf("%s\n", arr1);
// return 0;
//}
//
//#include<assert.h>
//char* my_strcpy(char* dest,const char* src)// A great god
// //const Put in the pointer variable * On the left , Modification is *p, in other words : Cannot pass p To change *p Value const char* p
// //const Put in the pointer variable * On the right , Decorated with pointer variables p In itself ,p Can't be changed char* const p
//{
// char* ret = dest;
// assert(dest != NULL);// Assertion -- Address invalid error
// assert(src != NULL);// Assertion
// while (*dest++ = *src++)// hold src Copy the string to dest Point to space , contain \0 character .
// {
// ;
// }
// return ret;
//}
//int main()
//{
// char arr1[] = "*********";
// char arr2[] = "hello";
// printf("%s\n", arr1);
// printf("%s\n", my_strcpy(arr1, arr2));
// return 0;
//}
// Realize it by yourself strlen- Find the string length
//#include<assert.h>
//int my_strlen(const char* arr)
//{
// int count = 0;
// assert(arr != NULL);// Guarantee the validity of the pointer
// while (*arr != '\0')
// {
// count++;
// arr++;
// }
// return count;
//}
//int main()
//{
// char arr[] = "abcdefg";
// int len = my_strlen(arr);
// printf("%d\n", len);
// return 0;
//}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
边栏推荐
- 蛰伏两年!瓴盛科技首款AIoT芯片发布:三星11nm工艺,集成NPU内核!
- 网络RJ45接口详解
- Live video Number supports product playback
- iptables防火墙端口规则配置
- 频谱分析仪的性能参数
- Video Number Xiaobai starting operation guide
- 食品安全 | 面包含盐量也会超标?几招教你正确吃面包!
- Apple supplier JDI plans to sell Baishan LCD plant and equipment for us $675million
- Functions brought by the binding of official account and video Number
- VSC writes go, expected 'package' appears, found 'EOF‘
猜你喜欢

示波器参数详解

Power adapter global definition

Examples of AC simulation and S-parameter simulation of ADS simulation

Introduction to the principle of signal source

顿悟!百度强推的Redis天花板笔记,原来数据库是这样理解的

Shenzhen offline registration starrocks on AWS: how to conduct rapid unified analysis of real-time data warehouses

低码在数字化转型中扮演什么角色?

Introduction to CC cable of USB type-C

矢量网络分析仪(矢网)的校准

Centos8 creates wordpress+mysql error reports according to the official website of docker
随机推荐
DC-DC开关电源
The video number is more like a official account of version 2.0
"Queen's day on March 8" has doubled the sales of on-site viewers and video numbers?
About the difference between root and alias under localization
syntax error: non-declaration statement outside function bodygo 和 syntax error: unexpected {, expect
SMIC's net profit in the first half of the year was 1.386 billion yuan, and the n+1 process has entered the stage of customer product verification
Iptables configuration
Msg.value of solidity
TCP/IP详细图解
vmware虚拟机联网设置(win10自带虚拟机安装win7)
矢量网络分析仪(矢网)组成和原理简介
Mongodb create index
Five key considerations for network security budget planning in 2023
DC simulation example of ADS simulation
insight! Baidu pushed redis ceiling notes, which was originally understood by the database
Performance parameters of spectrum analyzer
示波器简介
Yu Chengdong: Huawei is trying to cope with the US chip ban
1.08 billion dollars! TCL technology acquires Samsung Suzhou 8.5 generation line: the production capacity will increase by 60% in the next year!
Video Number Xiaobai starting operation guide