当前位置:网站首页>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.
边栏推荐
- Brief introduction to the principle of spectrometer I
- VSC writes go, expected 'package' appears, found 'EOF‘
- Yu Chengdong: Huawei is trying to cope with the US chip ban
- GIS数据漫谈(六)— 投影坐标系统
- #夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)
- 明德生物:公司暂未有产品被列入WHO推荐清单
- Examples of AC simulation and S-parameter simulation of ADS simulation
- Apple supplier JDI plans to sell Baishan LCD plant and equipment for us $675million
- Live video Number supports product playback
- Power adapter global definition
猜你喜欢

电源适配器 全球定义

What role does low code play in the digital transformation?

USB Type-C 之CC线简介

Introduction to CC cable of USB type-C

#夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)

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

互联智能,如何定义下一代网络变革

Detailed explanation of oscilloscope parameters

Brief introduction to the principle of spectrometer II

欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务
随机推荐
MediaTek has submitted an application to the US side, striving to supply goods to China after September 15
After CentOS uses docker to run mysql, the remote connection needs to open the port
Musk uses live pigs to show a new brain computer interface technology: it can read pig brain information in real time
长江存储推出自有存储品牌“致钛”,首款SSD产品曝光
MongoDB初始化
微信公众号授权登录后报redirect_uri参数错误的问题
Modifier modifier modifier of solidity _;
Video number from 2-3 games per week to 3 games per day
Random talk on GIS data (VI) - projection coordinate system
有一种密码学专用语言叫做ASN.1
一文简述:SRv6基本原理
Detailed explanation of oscilloscope parameters
MongoDB初始化操作
Go的sleep
蛰伏两年!瓴盛科技首款AIoT芯片发布:三星11nm工艺,集成NPU内核!
DC-DC switching power supply
The revenue of Shanghai silicon industry in the first half of the year was 850million yuan, an increase of 30.53% year on year! Various product certifications are accelerating
Changjiang storage launched its own storage brand "Zhiti", and the first SSD product was exposed
Video Number Xiaobai starting operation guide
Introduction to advanced design system (ads) 2009 RF simulation