![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
jclih
阳光,玻璃房,躺椅,macbook pro
展开
-
c语言二级指针与指针数组
一、代码int main(int argc, const char * argv[]) { int a[] = {1,2,3}; int b[] = {4,5,6}; int c[] = {7,8,8}; int* arr[] = {a,b,c}; int** p = arr; printf("a[0] = %d\n",a[0]); ...原创 2019-05-19 18:38:05 · 1493 阅读 · 0 评论 -
c/c++通过地址偏移访问或修改变量
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct Person { char c1; int t1; char c2; int t2;} myPerson;void test() { myPerson mp = {1,100,2,200}; /* ...原创 2019-07-14 15:20:58 · 1477 阅读 · 0 评论 -
C/C++版AES加密实现
一、参考文档1.https://www.jianshu.com/p/3840b344b27c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation2.https://songlee24.github.io/2014/12/13/aes-encrypt/...原创 2019-07-11 09:13:36 · 1220 阅读 · 0 评论 -
c/c++ base64加密实现
#include<iostream>#include<string>#include<bitset>#include<vector>#include<stdlib.h>#include<time.h>#include<sstream>typedef std::bitset<8> byte...原创 2019-07-11 17:03:54 · 591 阅读 · 0 评论 -
c/c++ sizeof与strlen的区别
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<stddef.h>void test01() { //sizeof统计 \0,strlen不统计\0,遇到\0就结束 char str[] = "hello\012world"; // \012是八进制,下转十进制...原创 2019-07-21 18:45:52 · 212 阅读 · 0 评论 -
c/c++ 结构体嵌套结构体的偏移量计算
#include<stdio.h>#include<stddef.h>struct Person{ char a; int b;};struct Person2{ char c; int d; struct Person e;};void test01() { struct Person2 p2 = {'c',10,'a',20}; i...原创 2019-08-03 11:17:03 · 666 阅读 · 0 评论 -
结构体所占字节的计算
#include<stdio.h>#pragma pack(show) // 8 默认对齐模数 生成解决方案的时候,会输出“杂项”说明,说明默认对齐模数比//对于自定义数据类型,内存对齐规则如下://1. 从第一个属性开始,偏移量为0//2. 从第二个属性开始,地址要放在该类型的整数倍与对齐模数比中的最小值的整数倍上 //3. 所有的属性都计算结束后,整体再做二次对齐,整体...原创 2019-08-03 12:31:40 · 573 阅读 · 0 评论 -
c/c++ 通过异或运算实现两个数的交换
void test07() { int num1 = 2; int num2 = 3; printf("交换前:"); printf("num1= %d,num2 = %d\n", num1, num2); num1 = num1 ^ num2; num2 = num1 ^ num2; num1 = num1 ^ num2; printf("交换后:"); printf("nu...原创 2019-07-28 15:43:01 · 1131 阅读 · 0 评论 -
c/c++ 如何定义数组的指针
#include<stdio.h>#include<stdlib.h>#include<string.h>//如何定义数组的指针(三种方式)//先定义出数组的类型,再通过类型创建数组的指针void test01() { int arr[] = {1,2,3,4,5}; typedef int(ARRAY_TYPE)[5]; // ARRAY_...原创 2019-07-28 17:16:26 · 3078 阅读 · 0 评论 -
c语言_二叉排序树增删
一、tree.h#pragma once#include<stdio.h>#include<stdlib.h>typedef struct binary_sort_tree { int* data; void* left; void* right; char ptr;}bst;#define BST_SIZE sizeof(bst)bst* tre...原创 2019-06-24 16:42:05 · 140 阅读 · 0 评论 -
c语言_贪吃蛇
c语言_贪吃蛇一、Snake.h#pragma once#define WIDTH 60#define HIGH 20int score = 0;//偏移量int dx = 0;int dy = 0;int lx = 0;int ly = 0;struct Body{ //横坐标 int x; //纵坐标 int y;};struct Snak...原创 2019-06-09 19:38:16 · 450 阅读 · 0 评论 -
c语言字符串的操作
一、代码/** 字符串去空格 */void trimStr(char* str){ int index=0; int readIndex = 0; while (*(str+readIndex)) { if(str[readIndex]!=' '){ str[index++] = str[readIndex++]; ...原创 2019-05-19 19:25:00 · 154 阅读 · 0 评论 -
c语言二级指针与二维数组
一、二维数组的地址不能赋给二级指针的原因int arr[][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };int** p = arr;二、指针遍历二维数组int* p1 = arr; for (int i = 0; i < sizeof(arr)/sizeof(arr[0][0]); i++) { printf("%d ",*p1++)...原创 2019-05-20 15:00:56 · 1782 阅读 · 0 评论 -
c语言随机数的产生
#include <stdio.h>#include <stdlib.h>#include <time.h>int main(int argc, const char * argv[]) { //添加随机数种子 srand((size_t)time(NULL)); for (int i = 0; i< 10; i++) { ...原创 2019-05-20 21:31:34 · 246 阅读 · 0 评论 -
c语言统计字符个数
1.统计各字符串出现的次数int main(int argc, const char * argv[]) { char chs[] = "fjadsjfjdsajfkjdskj"; int arr[26] = {0};//26个字母 for (int i = 0; i < sizeof(chs); i++) { if(*(chs+i)){ ...原创 2019-05-21 23:00:01 · 24814 阅读 · 2 评论 -
c语言二级指针开辟空间
一、图示二、代码int** p = (int**)malloc(sizeof(int*)* 3);//p中存的地址是开辟的空间的首地址 for (int i = 0; i < 3;i++) { *(p + i) = (int*)malloc(sizeof(int) * 3);//p+i中存的地址是开辟的空间的首地址 } for (int i = 0; i < 3...原创 2019-05-28 09:13:53 · 2354 阅读 · 1 评论 -
c语言结构体指针使用
一、代码#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>struct student1{ char* name; int age; char* sex; int* score; char* addr;};typede...原创 2019-05-28 14:20:55 · 183 阅读 · 0 评论 -
c语言大文件排序
一、生成大文件int main(void) { FILE* fp = fopen("D:/数据.txt","w"); if (!fp) { printf("打开文件失败/n"); return -1; } srand((size_t)time(NULL)); for (int i = 0; i < SIZE;i++) { fprintf(fp,"%d\n"...原创 2019-05-31 10:26:13 · 518 阅读 · 0 评论 -
c语言文件操作
一、fgetcint main(void) { FILE* fp = fopen("D:/hello.txt","r"); if (!fp) { printf("文件无法打开!"); return -1; } char ch; while ((ch=fgetc(fp))!= EOF) { printf("%c",ch); } puts(""); fclose...原创 2019-05-29 14:46:12 · 196 阅读 · 0 评论 -
c语言复制大文件
代码:#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#define SIZE 1024*1024*8int main(int argc, const char * arg...原创 2019-06-02 14:16:39 · 474 阅读 · 0 评论 -
c/c++ 二维数组作函数的参数
#include<stdio.h>#include<string.h>#include<stdlib.h>//二维数组作函数的参数,退化成一个指向一维数组的指针变量void printArray(int(*p)[3],int row,int col) { for (int i = 0; i < 3;i++) { for (int j =...原创 2019-07-28 17:43:40 · 235 阅读 · 0 评论