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的更多相关文章

  1. 因为没用过,所以没想过的--goto

    今天读了读 Rui Maciel 大神写的 mjson parser,mjson 解析器是一个使用 ISO C 实现的小型 JSON 解析器.嵌入式项目中使用到了该解析器,随即拿出来看看. 看到如下代 ...

  2. 也说python的类--基于python3.5

    在面向对象的语言中,除了方法.对象,剩下的一大重点就是类了,从意义上来讲,类就是对具有相同行为对象的归纳.当一个或多个对象有相同属性.方法等共同特征的时候,我们就可以把它归纳到同一个类当中.在使用上来 ...

  3. ORACLE NUMBER类型Scale为0引发的问题

    今天遇到了一个很有意思的NUMBER类型Scale引发的问题,我用一个简单的测试用例来展示一下这个案例.假如有个TEST的表,有个字段类型为NUMBER,我插入下面两条数据 CREATE TABLE ...

  4. python面向对象基础

    面向对象基础 1. 简述 编程方式: 面向过程: 根据代码在脚本的堆叠顺序,从上到下依次执行 函数式编程:将相同功能的代码封装到函数中,直接调用即可,减少代码重复性 面向对象:对函数进行分类和封装,将 ...

  5. c程序辨别系统是64位 or 32位

    #include <stdio.h> int main(void) { int i = 0x80000000; ){ printf("i = %d\n", i); pr ...

  6. php写插件

    1.写在最前 随着互联网飞速发展,lamp架构的流行,php支持的扩展也越来越多,这样直接促进了php的发展. 但是php也有脚本语言不可避免的问题,性能比例如C等编译型语言相差甚多,所以在考虑性能问 ...

  7. 【系统移植】Android系统移植

    $ . .. Device     . SimulatorWhich would you like] Build type choices are. release     . debugWhich ...

  8. python 将数据随机分为训练集和测试集

    # -*- coding: utf-8 -*- """ Created on Tue Jun 23 15:24:19 2015 @author: hd "&qu ...

  9. #ifdef _cplusplus (转)

    原文不可考,转载链接:http://blog.csdn.net/owldestiny/article/details/5772916 有发现原文的请告知,我会及时更新. 时常在cpp的代码之中看到这样 ...

随机推荐

  1. Javascript添加事件的addEventListener()及attachEvent()区别分析,事件委托

    Mozilla中: addEventListener的使用方式: target.addEventListener(type, listener, useCapture); target: 文档节点.d ...

  2. 总结一下classpath

    今天好好研究了一下Java的classpath,什么是classpath呢?classpath就是我们输入 java xxx 的时候Java执行环境搜索xxx类文件的路径.指定这个路径有两种方式,第一 ...

  3. Linux中获取本机网络信息的几个函数及应用

    一.读取/etc/hosts 几个函数 头文件<netdb.h> 1.void sethostent(int stayopen);//开打/etc/hosts 配置文件 2.struct ...

  4. iOS开发——UI进阶篇(十二)事件处理,触摸事件,UITouch,UIEvent,响应者链条,手势识别

    触摸事件 在用户使用app过程中,会产生各种各样的事件 一.iOS中的事件可以分为3大类型 触摸事件加速计事件远程控制事件 响应者对象在iOS中不是任何对象都能处理事件,只有继承了UIResponde ...

  5. Android学习笔记(七)——常见控件

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! Android 给我们提供了大量的 UI控件,下面我们简单试试几种常用的控件. 一.TextView 在布局文 ...

  6. python __file__ 与相对路径

    用__file__ 来获得脚本所在的路径是比较方便的,但这可能得到的是一个相对路径,比如在脚本test.py中写入: #!/usr/bin/env pythonprint __file__ 按相对路径 ...

  7. [codeforces 317]A. Perfect Pair

    [codeforces 317]A. Perfect Pair 试题描述 Let us call a pair of integer numbers m-perfect, if at least on ...

  8. git 忽略文件权限

    git config --add core.filemode false 发现.git/config 中新增了一行: [core] ... filemode = false ref: http://b ...

  9. [mysql] Some non-transactional changed tables couldn't be rolled back

    使用peewee的事务时,碰到一个郁闷的问题,事务似乎无效! 于是简化了下模型,写了简单的测试代码,发现问题,如题所示. 找到解答: https://github.com/etianen/django ...

  10. Mybatis 3.3.0 Log4j配置

    最近做一个SSM学习项目,配置log4j,mybatis用下面的方式配置,不管用,打印不出执行的SQL语句. log4j.logger.java.sql.Connection=DEBUGlog4j.l ...