您的位置:首页 > 编程语言 > C语言/C++

本周总结

2016-08-12 18:54 281 查看
本周总结
本周一开始学习了指针的定义,指针的类型,指针的实质是变量。(http://blog.csdn.net/qq_35576100/article/details/52153603)
本周二学习的是指针与一维数组的简单交集,二维数组也是相对与一维数组多个集合在一块的行数组。(http://blog.csdn.net/qq_35576100/article/details/52163753)
本周三学习了函数指针,函数指针的三部曲:复制函数名;抠掉函数名换成(*p)(xx);之后再调用函数指针传入参数。
(http://blog.csdn.net/qq_35576100/article/details/52174964)
本周四学习的是字符串的定义,字符串的多种定义方式,以及字符串的打印是直接打印函数地址就能直接打印出字符串。
        (http://blog.csdn.net/qq_35576100/article/details/52184171)
#include<stdio.h>
#include<Windows.h>
/*逐一打印字符*/
void main(){
char str[] ={"I love U"};
char *p = str;
while(*p){
printf("%c",*p);
Sleep(1000);
p++;
}
getchar();
return;
}

输入字符串,用除api的方式进行判断
#include<stdio.h>
int fun(char *p,char *p1,int a){
for(int i = 0;i<a;i++){
if(*(p+i)!=*(p1+i)){
return -1;
}
}
return 0;
}

void main(){
printf("请输入两个字符串分别回车:");
char ch[1000] = "0";
char *p = ch;
char ch1[1000] = "0";
char *p1 = ch1;
scanf("%s",ch);
scanf("%s",ch1);
if(sizeof(ch)/sizeof(char)!=sizeof(ch1)/sizeof(char)){
printf("$ -1 $");
}else
printf("$ %d $",fun(p,p1,sizeof(ch1)/sizeof(char)));
getchar();
}
<span style="white-space:pre">						</span>//矩阵对角线之和
#include<stdio.h>
int fun(int (*p)[3]){
int S = 0;
for(int i = 0;i<3;i++){
S+=*(*(p+i)+i);
}
return S;
}

void main(){
int a[][3] ={{1,2,3},{4,5,6},{7,8,9}};
printf("矩阵对角线之和为%d",fun(a));
getchar();
return;
}

#include <stdio.h>
/*打印从大到小的三个数*/
int main()
{
int a,b,c,t;
scanf("%d %d %d",&a,&b,&c);
if ( a < b )
{
t = a;
a = b;
b = t;
}
if( a < c )
{
t = a;
a = c;
c = t;
}
if( b < c )
{
t = b;
b = c;
c = t;
}
printf("%d %d %d",a,b,c);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息