fill是按照单元来赋值的,所以可以填充一个区间的任意值

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
typedef long long ll;
using namespace std;
#define INF 1e9+7
int main()
{
int a[100];
fill(a,a+10,100);
for(int i=0;i<10;i++)
printf("%d ",a[i]);
return 0;
}

 

memset函数一般只用于赋初值为0或者-1

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
typedef long long ll;
using namespace std;
#define INF 1e9+7
int main()
{
int a[100];
memset(a,-1,sizeof(a));
for(int i=0;i<10;i++)
printf("%d ",a[i]);
return 0;
}

  

如何给数组用fill函数和memset函数给数组赋初值的更多相关文章

  1. memset函数使用

    函数原型 void *memset(void *s,int c,size_t n): 功能 将已开辟内存空间 s 的首 n 个字节的值设为值 c. 头文件  #include<memory.h& ...

  2. 【C++】fill函数,fill与memset函数的区别

    转载自:https://blog.csdn.net/liuchuo/article/details/52296646 memset函数 按照字节填充某字符在头文件<cstring>里面fi ...

  3. C语言中的memset函数和数组指针

    代码: #include <iostream> #include <cstring> using namespace std; int main(){ ] = {}; mems ...

  4. 批量初始化数组和memset函数

    对于数组的初始化有一下三种方式: int  a[]={1,2,3,4,5} //通过判断初始化值得个数来却仍数组长度 int b[5]={1,2,3} //数组长度为5,可是初始值却只有三个,因此,不 ...

  5. 关于数组的初始化memset函数

    关于数组的初始化memset函数 其实memset复制时按bit8个8个的赋值,有兴趣的可以自己百度.

  6. [转载]C++二维动态数组memset()函数初始化

    来源:https://blog.csdn.net/longhopefor/article/details/20994919 先说说memset函数: void *memset(void *s,int ...

  7. memset()函数的使用

    1.概述 memset()函数,称为按字节赋值函数,使用时需要加头文件 #include<cstring>或者#include<string.h>.通常有两个用法: (1)用来 ...

  8. memset函数详解

    语言中memset函数详解(2011-11-16 21:11:02)转载▼标签: 杂谈 分类: 工具相关  功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大 ...

  9. 深入学习 memset 函数

    最近,和同学讨论了一下memset函数,趁着周五空闲做一总结. memset函数最常用的功能就是初始化数组了(主要是置零),如 #include <iostream> #include & ...

随机推荐

  1. 线程绑定CPU核-sched_setaffinity

    CPU亲合力就是指在Linux系统中能够将一个或多个进程绑定到一个或多个处理器上运行. 一个进程的CPU亲合力掩码决定了该进程将在哪个或哪几个CPU上运行.在一个多处理器系统中,设置CPU亲合力的掩码 ...

  2. c# json 排版

    public static string PraseToJson(string json) { try { JsonSerializer s = new JsonSerializer(); JsonR ...

  3. 【面试题046】求1+2+...+n

    [面试题046]求1+2+...+n 题目:     求1+2+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C).   思 ...

  4. bzoj 3376 [Usaco2004 Open]Cube Stacking 方块游戏——带偏移量的并查集

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3376 带偏移量的并查集. #include<iostream> #include ...

  5. 【转】python的复制,深拷贝和浅拷贝的区别

    在python中,对象赋值实际上是对象的引用.当创建一个对象,然后把它赋给另一个变量的时候,python并没有拷贝这个对象,而只是拷贝了这个对象的引用 一般有三种方法, alist=[1,2,3,[& ...

  6. 构造函数参数new class[0]的作用

    new Class[0];就是传一个长度为1的Class数组过去.内容为null. new Class[0]表示有零个元素的Class数组,即空数组,与传入null结果是一样的,都表示取得无参构造方法 ...

  7. Spring Web MVC 的HandlerMapping的使用之-------SimpleUrlHandlerMapping

    转自:https://www.2cto.com/kf/201401/271141.html Spring MVC教程 映射处理器Handler Mapping 一.简析映射处理器 在spring mv ...

  8. Redux API之Store

    Store Store 就是用来维持应用所有的 state 树 的一个对象. 改变 store 内 state 的惟一途径是对它 dispatch 一个action. Store 不是类.它只是有几个 ...

  9. Http协议-概要

    Http协议(超文本传输协议)是位于TCP/IP结构中的应用层的一种传输协议,规定了万维网服务器之间相互通信的规则.比如比较常见的Web浏览器客户端与应用服务器的通信!万维网服务器之间互相通信的时候往 ...

  10. apache配置中的小细节

    configuration error: couldn’t perform authentication错误的解决办法 configuration error: couldn’t perform au ...