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. python-多线程3-生产者消费者

    '''生产者和消费者''' ''' 用python写一个多线程的生产者和消费者 生产者x x>0,有东西,print(不生产) x=0,没东西,print(生产) for循环 消费者x x=0, ...

  2. Python实现结对编程项目

    Github (李昆乘)(陈俊豪) 开发流程 PSP2.1 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 ...

  3. listen 55

    There are also green card qualifiers for some non-citizens who invest in America, and for refugees.难 ...

  4. Linux下的磁盘缓存

    转自:http://blog.csdn.net/cywosp/article/details/21126161 前段时间在开发一个使用SSD做缓存的系统,在高速写入数据时会出现大量的磁盘缓存.太多的磁 ...

  5. codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)

    题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  6. 四连测Day4

    四连爆炸 卡我常数 好像被AluminumGod拉到了创客...哇我这个天天爆炸的水平可能会被其他三位dalao吊起来打 orz Edmond-Karp_XiongGod orz Deidara_Wa ...

  7. PowerDesigner根据SQL文件生成PDM数据字典

    当PowerDesigner不能直接连接到数据库的时候,可以用到下面这个方法生成数据字典(直接连接数据库生成数据字典在上次随笔中有介绍). 具体操作步骤截图: ↓↓↓这里选择的sql文件是从数据库导出 ...

  8. 【Lintcode】103.Linked List Cycle II

    题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...

  9. poj3422K方格取数——最大费用最大流

    题目:http://poj.org/problem?id=3422 最大费用最大流: 拆点,在自点之间连两条边,一条容量为1,边权为数字:一条容量为k-1,边权为0:表示可以走k次,只有一次能取到数字 ...

  10. java:Socket介绍(一)

    Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面,对用户来说,一组简单 ...