1、电脑任务栏的显示和隐藏
教你个简单的方法:按下 Ctrl+Alt+Del 键,打开任务管理器->”进程”选项卡->找到 explorer.exe ->点结束进程->点“文件”->在新建任务中输入“explorer.exe ”,再点“确定”。
2、数据类型的作用:指定解析方式,指定解析内存块的大小
简单的猜数游戏
/*========while的使用 return的使用 头文件的添加 分号============*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int price,num=0,time=0;
price=rand()%100+1;
printf("Please guess a number:");
while(num!=price)
{
scanf("%d",&num);
if (num==price)
{
printf("Right!\n");
/*return 0;*/
}
else if(num<price)
{
printf("Please input a bigger number:");
}
else if(num>price)
{
printf("Please input a smaller number:");
}
time++;
}
printf("The total time is:%d\n",time);
return 0;
}
循环语句;for(初始条件;循环判断;其他操作)
{ }
while(循环判断)
{ }
do
{ }
while(循环判断)
goto语句;一般不用
/*实现1+...+100*/
#include <stdio.h>
int main(void){
int i,sum=0;
i=1;
loop: if(i<=100){
sum=sum+i;
i++;
goto loop;
}
printf("%d\n",sum);
return 0;
}
跳出循环
break:跳出switch语句;跳出当前循环语句
return 主要用于函数的返回,其实质就是根据条件相应提前结束函数的运行,当然也就能结束函数题的运行
continue 提前结束本次循环 进入下一次循环
3、根据编译器的不同 int占据内存的大小不同
51单片机的C语言中int 代表2字节(16位) 同理32位的RAM处理器的C语言中 int 代表4字节
PC端软件的编译器则会根据操作系统或处理器定义为 4字节或8字节
数组 结构体
重要内容
4、函数——一个输入输出的工具
/*=====函数的语法======*/
[] fun_name(argument)
{
statement(s);
return [];
}//[]表示可由可无
C语言中函数的分类:库函数和自定义函数
库函数:
1、Standard C I/O 标准的输入输出函数
2、Standard C String &Character 处理的是字符和字符串
3、Standard C Math 数学相关的函数
4、Standard C Time & Date 时间和日期相关的函数
5、Standard C Memory 内存相关的函数
6、Other Standard C Function 其他一些标准C函数
函数的声明和定义
形参的作用是什么 就是向编译器的一种解释 函数调用时候需要遵循的规则 否则会报错或警告
形参可以不用参数名 直接写参数类型就好了
指针
指针所占的内存与操作系统有关 32位windows是4字节 64-8
程序的内存分配
一个有c/c++编译的程序占用的内存分为以下几个部分:
栈区(stack) 堆区(heap)全局区(静态区) 文字常量区、程序代码区
内存的分配和释放 内存的存储方式 存储效率
char **a[3] [4] ;printf(“%d”,sizeof(a));
a为一个指针数组 每个指针占4个字节(32位),则4*3*4=48;
C语言动态数组的分配及实现 见收藏夹
Exit() 是电脑函数。
函数名: exit()
所在头文件:stdlib.h
功 能: 关闭所有文件,终止正在执行的进程。
exit(1)表示异常退出.这个1是返回给操作系统的。
exit(x)(x不为0)都表示异常退出
exit(0)表示正常退出
exit()的参数会被传递给一些操作系统,包括UNIX,Linux,和MS DOS,以供其他程序使用。
stdlib.h: void exit(int status);
参 数 : status //程序退出的返回值.
int j = 0;
int a[10];
a[++j]=j++;
int j = 0;
int a[10];
a[++j]=++j;
int j = 0;
int a[10];
a[j++]=j++;
int j = 0;
int a[10];
a[j++]=++j;
上面四个式子执行后,数组a的值分别是什么
a[1]=0 j=2
/*Problem B:请写一个程序,对于一个m行m列的(1<m<10)的方阵,求其每一行,每一列及主副对角线元素之和,最后按照从大到小的顺序依次输出。
输入说明:共一组数据,输入的第一行为一个正整数,表示m,接下来的m行,每行m个整数表示方阵元素。
输出说明:从大到小排列的一行整数,每个整数后跟一个空格,最后换行。
输入样本:
4 15 8 -26
31 24 18 71
-3-9 27 13
17 21 38 69
输出样本:
159 145 144 13581 60 44 32 2827*/
/*
time 7.11 problem
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
int m,*array = 0,*result = 0;
void aInput()
{
int i=0,j=0,num=0;
scanf("%d",&m);
//分配空间
array = (int *)malloc(sizeof(int)*m*m);
result = (int *)malloc(sizeof(int)*m+2);
if(array == 0)
{
printf("quit!------");
exit(0);
}
//动态输入数组
for(i = 0;i<m;i++){
for(j = 0;j<m;j++){
scanf("%d",&array[i*m+j]);
}
}
}
void aCount()
{
int i = 0,j = 0,xsum = 0,ysum = 0;
for(i = 0;i<m;i++)
{
for(j = 0;j<m;j++)
{
xsum +=array[i*m+j];
ysum +=array[i+j*m];
}
result[i*2] = xsum;
xsum = 0 ;
result[i*2+1] = ysum;
ysum = 0;
}
for(i = 0;i<m;i++){
xsum += array[i*m+i];
ysum += array[i*m+(m-i-1)];
}
result[2*m]=xsum;
result[2*m+1]=ysum;
}
void aOutput()
{
int i,j,temp;
for(i = 0;i<2*m+2;i++)
{
int flag=0;
for(j = 0;j<2*m+2-i;j++)
{
if(result[j]>result[j+1])
{
temp = result[j];
result[j] = result[j+1];
result[j+1] = temp;
flag=1;
}
}
if (flag==0)
{
return ;
}
}
}
int main(void)
{
int i;
aInput();//输入数据
aCount();//数据计算
aOutput();//数据排列
for(i=2*m+1;i>=0;i--)
{
printf("%d ",result[i]);
}
return 0;
free(array);
free(result);
}
标识符的作用域:局部作用域 、全局作用域、块作用域、文件作用域
生命周期:生命周期与变量在内存中的存储区有很大关系
存储区分为:栈区 堆区 全局区 代码区
存储类型:控制变量存储在哪里 相应的有四个关键字
auto 默认 在栈区
static 全局区(静态区)
register 建议性的知识编辑器将变量直接安排在寄存器上
extern:告诉编译器 这个变量是在外部文件定义的,这里只是引用
循环语句的几种退出方式的注意点
break 退出当层循环 常与if联用 ; 退出switch语句
return 暴力退出
continue 提前结束本次循环 进入下一次循环
设置flag:当满足一定条件时,设置flag的值,在外层判断就可以很轻松的跳出循环,这个方法很常用
goto语句
C编程的基本框架包含相应的头文件、宏定义、全局变量、函数声明、主函数的编写
C语言的核心是指针
C++的核心是面向对象、模板和泛型编程
计算机位数 CPU位数 操作系统位数
关于指针的9个必须弄懂的问题
http://www.cjjjs.com/paper/bcyy/6232015151112874.html
为什么会产生数据结构这门学科;因为内存在计算机中的地址是线性排列的 计算机的所有指令和数据都是经过内存到CPU的,也就是说,所有的数据都要在内存中存放,而我们现实生活中很多非线性结构不能由内存结构直接表示出来,因为内存是线性的,只能表示线性的,所有有了数据结构这门学科,我们要想办法把非线性的转变成线性的。
数组按行排列
函数名、函数类型、函数地址、函数指针
http://www.cjjjs.com/paper/bcyy/624201541100810.html
strlen到尾0结束
sizeof字符串内存大小
strcpy函数原型
char strcpy(char *a,char *b){
while(*(a++)=*(b++))!=0)
return a;
}
debug和release版本的区别
结构体内存分配对齐深入理解
/*32位系统下的说明*/
struct a
{
int b;/*本身占用4个字节,但是因为下面最宽数据类型是double,要让它整除,所以占用8个字节,编译器自动对齐(参考第一点)*/
double c;/*这个就是最宽数据类型,占用字节就是它本身8个字节*/
char d[9];/*本身每个char占用1个字节,定义了9个char所以大家认为一共用9个字节,但是其实是16个字节,因为要被double整除(参照第二点)*/
};
void main()
{
prinf("%d",sizeof(struct a));//所以最后输出为32
}
动态链表的建立
#include <stdio.h>
#include <stdlib.h>
#define len sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head,*p1,*p2;
n=0;
p1=p2=(struct student *)malloc(len);
scanf("%d%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(len);
scanf("%d%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
int main()
{
struct student *pt;
pt=creat();
printf("%d\n%f\n",pt->num,pt->score);
return 0;
}
自创程序如下
#include <stdio.h>
#include <stdlib.h>
#define len sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};
struct student*creat(void)
{
struct student *head,*p1,*p2;
head=p1=p2=(struct student *)malloc(len);
scanf("%d%f",&p1->num,&p1->score);
while(p1->num!=0)
{
p1=(struct student *)malloc(len);
scanf("%d%f",&p1->num,&p1->score);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
void main()
{
struct student *pt;
pt=creat();
printf("%d\n%f\n",pt->num,pt->score);
}