C语言
lzw~
这个作者很懒,什么都没留下…
展开
-
#ifdef
#ifdef判断某个宏是否被定义,若已定义,执行随后的语句原创 2020-07-22 09:52:33 · 123 阅读 · 0 评论 -
枚举类型enum
枚举enum 23 enum{ ST_IDLE, ST_PLAY, ST_PAUSE};1.枚举是一个集合,集合中的元素(枚举成员)是一些整型常量,元素之间用逗号隔开2.第一个枚举成员的值默认为0原创 2020-06-18 11:06:35 · 288 阅读 · 0 评论 -
C开发工程师常见面试题
1:什么预编译?预编译又称预处理,是整个编译过程最先做的事情,即程序执行前的一些预处指令理工作。主要处理#开头的指令。如拷贝#include包含的文件代码、替换#define定义的宏、条件编译#if等。2:写一个“标准”宏,这个宏输入两个参数并返回较小的一个。#define Min(x,y) ((x)<(y)?(x):(y))3:如何避免头文件被重复包含?使用条件编译:#ifnd...原创 2020-02-15 22:24:56 · 5980 阅读 · 0 评论 -
C语言学习笔记(十五):面向接口编程
test.c#include<stdio.h>#include<string.h>#include<stdlib.h>#include"csocketimp.h"//初始化链接typedef void(*init_cSockeProtocol)(void** handle);//发送接口typedef void(*send_cSockeProtocol)(void* handle, char* sendData, int sendlen);//接收接口原创 2020-05-17 15:14:35 · 232 阅读 · 0 评论 -
C语言学习笔记(十四):动态库和静态库
静态库的创建在windows环境下1.创建一个空项目,类型选择“库”,名称和解决方案输入staticlib,点击确定2.头文件添加mylib.h源文件添加mylib.c3.mylib.h添加#pragma once#ifndef TEST_H#define TEST_Hint myadd(int a, int b);#endif // !TEST_H4.源文件mylib.c#include"mylib.h"int myadd(int a, int b){ return原创 2020-05-16 22:00:48 · 181 阅读 · 0 评论 -
C语言学习笔记(十三):函数指针
#include<stdio.h>//函数名就是函数的入口地址int myfunc(int a,char b) { printf("int myfunc(int a,char b)\n"); return 0;}void test01(){ //1.直接定义函数指针变量 int (*pfunc)(int, char) = myfunc; pfunc(50, 'p'); printf("pfunc size:%d \n", sizeof(pfunc));}in原创 2020-05-15 13:28:18 · 157 阅读 · 0 评论 -
C语言学习笔记(十二):my_strstr
#include<iostream>#include<stdio.h>using namespace std;char* my_strstr(const char* str,const char* sub){ const char* pstr = str; const char* psub = sub; while (*pstr != '\0') { if (*pstr != *psub) { pstr++; continue; }原创 2020-05-13 14:36:22 · 277 阅读 · 0 评论 -
C语言学习笔记(十 一):字符串反转
#include<iostream>#include<string.h>using namespace std;int inverse(char* src){ int len = strlen(src); char* p1 =src ; char* p2 = src + len - 1; while (p1 < p2) { char c = *p1; *p1 = *p2; *p2 = c; p1++; p2--; } retur原创 2020-05-12 23:56:51 · 133 阅读 · 0 评论 -
C语言学习笔记(十):const关键字
1:const 修饰指针变量#include<stdio.h>#include<iostream>using namespace std;int main(){ int a = 10; int b = 10; //const 在int* 前面,是不可以修改p所指向的地址里面的值的。此时不可以给*p赋值100 const int* p = &a;...原创 2020-04-22 20:36:40 · 110 阅读 · 0 评论 -
C语言学习笔记(九):野指针
在程序里面定义了一个野指针,当我们将这个指针free掉后这个指针就指向了一个不确定的内存空间,在代码的后续我们如果还对这个指针进行操作,则程序会报错。...原创 2020-04-22 19:45:35 · 130 阅读 · 1 评论 -
C语言学习笔记(八):argc和argv[1]的区别
atoi //把字符串转换成整型#include<opencv2/opencv.hpp>#include<iostream> using namespace std;int main(int argc,char * argv[]){ return 0;}argc为参数个数,默认argc为1,argv[0]为程序名称。如果输入一个参数,则arg...原创 2020-03-30 00:46:59 · 2686 阅读 · 0 评论 -
C语言学习笔记(七):extern的用法
extern关键字声明变量为外部变量假设此时有两个文件:a.cb.c我在a.c文件中定义了一个全局变量 int fd在文件b.c中我可以使用extern int fd;来引用a.c文件中的变量fd...原创 2020-04-21 01:43:15 · 136 阅读 · 0 评论 -
C语言学习笔记(六):数组越界问题
char string[10];char *str1="0123456789";strcpy(string, str1);printf("%s",string);由于str1字符串末尾有’\0’字符,所以该字符串拥有11个字节而数组大小是10个字节,使用strcpy造成了数组越界...原创 2019-10-23 17:49:00 · 235 阅读 · 0 评论 -
C语言学习笔记(五):内存分配
1:void GetMemory(char **p, int num){*p = (char *)malloc(num); //堆}void Test1(){char *str = NULL;GetMemory(&str, 100);strcpy(str, “xmgcc”);printf("%s\n", str);}输出内容:xmgccvoid Tes...原创 2019-09-10 21:21:35 · 135 阅读 · 0 评论 -
C语言学习笔记(四):结构体大小计算
结构体:对齐,填充,不填充计算大小的规律1.每一个成员的偏移量都必须是该成员字节数大小的倍数。第一个成员的偏移量都是0,一般可以不看2.结构体的大小必须是该结构体成员中字节数最大的倍数。填充的字节用[]表示最宽字节81 [3] 4 8struct X { char a; //1 int b; //4 double c; //8} S1;最宽字节81 [7] 8 4 ...原创 2019-09-11 19:11:08 · 161 阅读 · 0 评论 -
C语言学习笔记(三):数组
数组基础知识: 一维数组:int a[2] 二维数组: int a[2][3] 特性:内存是连续的 支持随机访问 数组名指向数组的首地址,是常量 每个数组元素的类型是一样的指针和数组short a[4];short *p = a;printf("%p\n",p+0);printf("%p\n",p+1);printf("%p\n",p+2);printf("...原创 2019-09-11 16:28:26 · 104 阅读 · 0 评论 -
C语言学习笔记(二):typedef的用法
此处LIST为struct LIST_T的别名原创 2019-09-11 10:28:00 · 103 阅读 · 0 评论 -
C语言学习笔记(一):链表的创建、遍历、插入和删除
结构体定义:struct Node{int data;struct Node *next;};链表的创建:struct Node* initLink(){struct Node *head;struct Node *tail;struct Node *newNode;head=(struct Node*)malloc(sizeof(struct Node));head-&g...原创 2019-07-28 20:46:29 · 105 阅读 · 0 评论