分析下列程序输出

#include<iostream>
#include<string.h>
using namespace std;
int main() {
char p1[]="abcd",*p2="ABCD",str[]="xyz";
strcpy(str+,strcat(p1+,p2+));
cout<<str;
return ;
}

程序输出xycdBCD

分析:

strcat(p1+2,p2+1); //返回以p1+2为首的字符串,即"cdBCD" 
strcpy(str+2,strcat(p1+2,p2+1)); //将"cdBCD"copy到str+2位置上,并覆盖后面的内容,此时str为"xycdBCD" 

1strcat/strcpy应用的更多相关文章

  1. strcpy函数在VS2015无法使用的问题

    一:原因:一般认为是vs准备弃用strcpy的,安全性较低,所以微软提供了strcpy_s来代替 然而,strcpy_s并没有strcpy好用,我们要想继续在VS2015中使用strcpy该怎么办 呢 ...

  2. 你必须知道的指针基础-4.sizeof计算数组长度与strcpy的安全性问题

    一.使用sizeof计算数组长度 1.1 sizeof的基本使用 如果在作用域内,变量以数组形式声明,则可以使用sizeof求数组大小,下面一段代码展示了如何使用sizeof: ,,,,,}; int ...

  3. strcpy 函数的实现

    原型声明:extern char *strcpy(char *dest,const char *src); 头文件:string.h   功能:把从src地址开始且含有‘\0’结束符的字符串赋值到以d ...

  4. Linux C 字符串函数 strlen()、strcat()、strncat()、strcmp()、strncmp()、strcpy()、strncpy() 详解

      strlen(返回字符串长度) 表头文件 #include <string.h> 定义函数 size_t strlen(const char *s); 函数说明 strlen()用来计 ...

  5. strncpy,strcpy

    strncpy不会为des自动添加“\0” strcpy遇空结束,自动添加结束符 结论: 1.使用strcpy时一定不能用于无结束符的字符串,因为strcpy依赖\0判断源字符串的结束 2.使用str ...

  6. strcpy strlen memcpy等的函数实现

    #include <assert.h> #include <string.h> #include <stdlib.h> #include <stdio.h&g ...

  7. 字符串strcpy

    strcpy函数的表达方式: //把一个char组成的字符串循环右移n个,如:“abcdefghi",n=2,移动后"hiabcdefgh" #include <i ...

  8. strlen(); strcpy(); strcat(); strcmp() ---笔记

    指针小知识点: int a =10; int *p=&a; int *q=p;        //p中保存的是a的地址 int *q=p;       //将p的值赋给q 作用是让q也指向a ...

  9. strcpy 库函数 拷贝函数

    strcpy 是在string.h 里面 #include "stdafx.h"#include "string.h"struct Student{int Se ...

随机推荐

  1. STM32.printf

    printf("\r\n this is a usart printf demo \r\n"); Use Micro LIB 需要勾选这个库 将串口定义成 printf 函数 #i ...

  2. AMS1117稳压模块

    AMS1117有降压稳压的作用.我们使用的是AMS1117-5,输出5V电压. 理论参数: 输出条件 最小值 理论值 最大值 理论电路图: 引脚图:

  3. openwrt的编译方法

    1.获取最新包 ./scripts/feeds update -a 2.安装包 ./scripts/feeds install -a 3.配置 make menuconfig 4.编译 make -j ...

  4. Shell变量知识进阶

    一,Shell中特殊且重要的变量 $0结合dirname和basename分别取出脚本名称和脚本路径 [root@192-168-3-163 scripts]# cat test.sh #!/bin/ ...

  5. c# &与&& 和 |与||的区别

    &:按位与,对两个条件都进行判断 &&:逻辑与,只要一个条件满足,另外一个条件就不会执行 同理: |:按位或,对两个条件都进行判断 ||:逻辑或,只要一个条件满足,另外一个条件 ...

  6. poj 2385 Apple Catching 基础dp

    Apple Catching   Description It is a little known fact that cows love apples. Farmer John has two ap ...

  7. shell 使用变量

    使用变量 使用一个定义过的变量,只要在变量名前面加美元符号即可,如: your_name="qinjx" echo $your_name echo ${your_name} 变量名 ...

  8. [原][译][physX]phsyX3.3.4官方文档物理引擎基本概念和例子介绍

    世界和物体: 物理世界包括集合的场景,每个包含的物体称为演员(Actors) 每个场景(Scene)都定义了自己的参考框架包含了所有的时间和空间 在不同的场景,演员不互相影响 演员通常有三种类型:刚体 ...

  9. [原][OSG][osgBullet][osgworks][bullet]编译osgBullet尝试物理引擎

    相关网址: 类似文章:http://blog.csdn.net/lh1162810317/article/details/17475297 osgBullet官网:http://osgbullet.v ...

  10. java数组声明和变式--record1

    ​ java声明数组方式: String[] namelist; int numlist[];//此声明为动态声明,不能指定长度,numlist[10] 静态声明的方式: int a[]={1,2,3 ...