c_test
1.int a[][4]={0,0};与int a[3][4] = {0};
元素不够的就以位模式初始化为0

a[第一维][第二维] 的大小,也就是最多存几个
int a[][3]={1,2,3,4,5,6,7,8};实际上等于
int a[][3]={ {1,2,3}, {4,5,6}, {7,8} };
有3个一维元素,所以一维大小为3
测试代码:
int main(void) {
][] = {};
; i < ; ++i) {
; j < ; ++j) {
printf("%d ", a[i][j]);
) printf("\n");
}
}
;
}
2.int k=10;
while(k=0) k=k-1;
则循环体语句一次也不执行
while中k=0,则while(0)判断为0后不再执行下面的语句
3.t=0; while(printf("*")) { t++; if(t>3)break; } 这段程序可执行几次 (4次)
int printf(const char *format, ...);
Upon successful return, these functions return the number of characters
printed (excluding the null byte used to end output to strings).
4.内存操作:将指针unsigned char* ptr的内容向后移动4个字节
*(ptr+4)=*ptr;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <time.h>
using namespace std;
#define debug(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
int main(void) {
;
unsigned char* ptr=(unsigned char *)&i;
; j < ; ++j) {
printf("%#x %#x\n", &i+j, ptr[j]);
}
*(ptr+) = *ptr;
; j < ; ++j) {
printf("%#x %#x\n", &i+j, ptr[j]);
}
;
}
5.将无符号变量unsigned int val进行字节序颠倒
//<< > &
//unsigned int val = 0xff000000;
unsigned int val = 0xff;
//val = ((val&0x000000ff)<<24)|((val&0x0000ff00)<<8) |( (val&0x00ff0000)>>8)| ((val&0xff000000)>>24);
val = ((val&)|((val&) |( (val&)| (val>>);
printf("%#x\n", val);
6.字符串逆转:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <time.h>
using namespace std;
#define debug(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
int main(void)
{
char *src = "hello,world";
char *dest = NULL;
int len = strlen(src);
dest = (); //要为\0分配一个空间
char *d = dest;
]; //指向最后一个字符
)
{
*d++ = *s--;
*d = ; //尾部要加上\0
}
cout << dest << endl;
free(dest); //使用完,应当释放空间,以免造成内存泄露
;
}
7.编写strcpy函数(10分) 已知strcpy函数的原型是 char *strcpy(char *strDest, const char *strSrc); 其中strDest是目的字符串,strSrc是源字符串。
(1)不调用C++/C的字符串库函数,请编写函数 strcpy
char *strcpyx(char *strDest, const char *strSrc){
assert((strDest!=NULL) && (strSrc !=NULL));//2分
char *address = strDest;// 2分
while( (*strDest++ = *strSrc++) != '\0')NULL;//2分
return address;// 2分
}
(2)strcpy能把strSrc的内容复制到strDest,为什么还要char * 类型的返回值?
答:为了实现链式表达式。 // 2分
例如 int length = strlen( strcpy( strDest, "hello world") );
c_test的更多相关文章
- 因为没用过,所以没想过的--goto
今天读了读 Rui Maciel 大神写的 mjson parser,mjson 解析器是一个使用 ISO C 实现的小型 JSON 解析器.嵌入式项目中使用到了该解析器,随即拿出来看看. 看到如下代 ...
- 也说python的类--基于python3.5
在面向对象的语言中,除了方法.对象,剩下的一大重点就是类了,从意义上来讲,类就是对具有相同行为对象的归纳.当一个或多个对象有相同属性.方法等共同特征的时候,我们就可以把它归纳到同一个类当中.在使用上来 ...
- ORACLE NUMBER类型Scale为0引发的问题
今天遇到了一个很有意思的NUMBER类型Scale引发的问题,我用一个简单的测试用例来展示一下这个案例.假如有个TEST的表,有个字段类型为NUMBER,我插入下面两条数据 CREATE TABLE ...
- python面向对象基础
面向对象基础 1. 简述 编程方式: 面向过程: 根据代码在脚本的堆叠顺序,从上到下依次执行 函数式编程:将相同功能的代码封装到函数中,直接调用即可,减少代码重复性 面向对象:对函数进行分类和封装,将 ...
- c程序辨别系统是64位 or 32位
#include <stdio.h> int main(void) { int i = 0x80000000; ){ printf("i = %d\n", i); pr ...
- php写插件
1.写在最前 随着互联网飞速发展,lamp架构的流行,php支持的扩展也越来越多,这样直接促进了php的发展. 但是php也有脚本语言不可避免的问题,性能比例如C等编译型语言相差甚多,所以在考虑性能问 ...
- 【系统移植】Android系统移植
$ . .. Device . SimulatorWhich would you like] Build type choices are. release . debugWhich ...
- python 将数据随机分为训练集和测试集
# -*- coding: utf-8 -*- """ Created on Tue Jun 23 15:24:19 2015 @author: hd "&qu ...
- #ifdef _cplusplus (转)
原文不可考,转载链接:http://blog.csdn.net/owldestiny/article/details/5772916 有发现原文的请告知,我会及时更新. 时常在cpp的代码之中看到这样 ...
随机推荐
- SQL双重游标(双重循环)--笔记
declare )='', )='', )='' --创建游标 declare @cursor cursor --设定游标欲操作的数据集 set @cursor=cursor for select s ...
- Redis Windows下安装部署
下载Redis 在Redis的官网下载页上有各种各样的版本,我这次是在windows上部署的,要去GitHub上下载.我下载的是2.8.12版的,相信大家百度一下就可以搜到,这就是我们需要的: 启动R ...
- iOS企业级开发初级课程-UIView与控件(20集)
UIView与控件向大家介绍了视图和控件之间的关系以及应用画面的建构层次.然后是对标签.按钮.文本框.文本视图.开关.滑块.分段控件.网页控件.屏幕滚动控件.等待控件.进度条.警告.动作选单.工具栏. ...
- Gunicorn 和 Nginx
Web Application Deployment Using Nginx Nginx is a very high performant web server / (reverse)-proxy. ...
- All Kind Of Conference(随时更新...)
收集一些前端开发的各种会议,里面有视频或者PPT,随时查看都还是很有收获的.还有要向这些演讲的前辈看齐- AC 2015:http://ac.alloyteam.com/2015/ AC 2016:h ...
- opencv png和jpg的叠加
char *bgFile = "C:/C_Project/HandTraining/Debug/res/bg.jpg"; FILE *file = fopen(bgFile, &q ...
- OpenCV加载图像并显示
从文件中读取一直一张图片,并加载出来 代码: #include "stdafx.h" #include "iostream" using namespace s ...
- java对txt文件内容追加
package com.test; import java.io.FileOutputStream; /** * 对txt文件在文本追加内容 * @author Wdnncey * */ public ...
- ffmpeg解码音频流
//初始化.注册编解码器 avcodec_init(); av_register_all(); avformat_network_init(); //选取测试文件 char* FileName=&qu ...
- spring mvc 避免IE执行AJAX时,返回JSON出现下载文件
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 --> <bean id="mappingJacksonHttpMessageConverter" c ...