如何给数组用fill函数和memset函数给数组赋初值
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函数给数组赋初值的更多相关文章
- memset函数使用
函数原型 void *memset(void *s,int c,size_t n): 功能 将已开辟内存空间 s 的首 n 个字节的值设为值 c. 头文件 #include<memory.h& ...
- 【C++】fill函数,fill与memset函数的区别
转载自:https://blog.csdn.net/liuchuo/article/details/52296646 memset函数 按照字节填充某字符在头文件<cstring>里面fi ...
- C语言中的memset函数和数组指针
代码: #include <iostream> #include <cstring> using namespace std; int main(){ ] = {}; mems ...
- 批量初始化数组和memset函数
对于数组的初始化有一下三种方式: int a[]={1,2,3,4,5} //通过判断初始化值得个数来却仍数组长度 int b[5]={1,2,3} //数组长度为5,可是初始值却只有三个,因此,不 ...
- 关于数组的初始化memset函数
关于数组的初始化memset函数 其实memset复制时按bit8个8个的赋值,有兴趣的可以自己百度.
- [转载]C++二维动态数组memset()函数初始化
来源:https://blog.csdn.net/longhopefor/article/details/20994919 先说说memset函数: void *memset(void *s,int ...
- memset()函数的使用
1.概述 memset()函数,称为按字节赋值函数,使用时需要加头文件 #include<cstring>或者#include<string.h>.通常有两个用法: (1)用来 ...
- memset函数详解
语言中memset函数详解(2011-11-16 21:11:02)转载▼标签: 杂谈 分类: 工具相关 功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大 ...
- 深入学习 memset 函数
最近,和同学讨论了一下memset函数,趁着周五空闲做一总结. memset函数最常用的功能就是初始化数组了(主要是置零),如 #include <iostream> #include & ...
随机推荐
- rust borrow and move
extern crate core; #[deriving(Show)] struct Foo { f : Box<int> } fn main(){ let mut a = Foo {f ...
- 机器视觉 Histogram of oriented gradients
Histogram of oriented gradients 简称 HoG, 是计算机视觉和图像处理领域一种非常重要的特征,被广泛地应用于物体检测,人脸检测,人脸表情检测等. HoG 最早是在200 ...
- 1135 Is It A Red-Black Tree(30 分)
There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...
- 【Lintcode】038.Search a 2D Matrix II
题目: Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence ...
- C#中使用GetCursorPos获取屏幕坐标
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; public POINT ...
- C# FileStream 按大小分段读取文本内容
该例子首先在C盘根目录创建一个名为'file1.txt'的文本文件. 然后再运行该例子.. 完整代码如下: 引入命名空间: [csharp] view plain copy print? using ...
- C# DataGridView的單元格中只能輸入數字
控件類型:DataGridView 控件名稱:dgvGift_Condition 裏面用到的:IsNumeric.NotePastText.RestoreText 等請參見 前一日志“TextBox中 ...
- 使用Spring的jdbcTemplate进一步简…
先看applicationContext.xml配置文件: 版权声明:本文为博主原创文章,未经博主允许不得转载.
- 使用gdb调试c程序莫名退出定位 exit 函数
gdb 程序名称 b exit //设置exit函数断点 run //运行程序 bt //查看程序调用堆栈,定位到exit所在行
- ios之CoreAnimation
CoreAnimation的好处: 1.高性能,简单的编程模块 2.像View一样,使用层级结构来构建负责的界面 3.轻量级数据结构,能使上百个动画同时执行 4.抽象的动画接口,允许动画在一个独立的线 ...