sizeof

Writing complex records to file

荒凉一梦 提交于 2019-11-29 20:42:37
问题 Hi I have defined some records in my project which may be consisted of other records and also dynamic arrays of normal data types and other records , it is n example of a record type Type1=record x:integer; end; Type2=record Y:array of X; str:string; end; When I tried to save one of variables of these records type to file with blockwrite function like this : var Temp1:Type2; begin setlength(temp1.y,100); blockwrite(MyFile,Temp1,sizeOf(Temp1); it just wrote as much as the size of pure record

sizeof:那些不为人知的小秘密

人走茶凉 提交于 2019-11-29 20:31:47
sizeof()到底是什么? 每当人们在一段代码中看到**sizeof()**时,许多人总是会认为这是一个库自带的函数,那它真就是一个函数吗?我们首先来看一下比较官方的解释: The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type(including aggregate types). This keyword returns a value of type size_t. 那 sizeof 到底是什么? sizeof 是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者类型所占的内存字节数。 其返回值类型为size_t,在头文件<stdio.h>中定义 所以请记住: sizeof 为操作数,而且是单目操作数,它并不是一个函数。 我们来看一下sizeof有哪些不为人知的小秘密 1.sizeof后需不需要加小括号()? 1.当sizeof的操作数是类型时必须加括号(); # include <stdio.h> int main ( ) { printf ( "%d\n" , sizeof ( int ) ) ; printf ( "%d\n" , sizeof ( double ) ) ; }

AC自动机总结

孤街醉人 提交于 2019-11-29 19:47:14
AC自动机总结 AC自动机简述 功能 多模板串对单个或多个串的匹配问题 主体思想 原理同 \(kmp\) , 在 \(trie\) 树上使用变种的 \(kmp\) 实现 需要数组 : \(trie[N][26],fail[N]\) \(fail\) 即我们所说的失配函数, \(trie[]\) 则略有变更 准确一点得说, \(fail\) 函数是不需要知道后继字母的失配 而 \(trie\) 树上的节点经过处理后,就可以直接 \(O(1)\) 访问后继每一种字母的情况的下一个位置,不需要再一次次失配 预处理 AC自动机的预处理与 \(kmp\) 的预处理只有一点不同 \(kmp\) 的 失配数组 \(nxt[N]\) , 是在不知道下一位的字母,一次次失配直到与下一位匹配 int j=0; for(int i=1;i<=n;++i){ while(j && s[i]!=t[j+1]) j=nxt[j]; if(s[i]==t[j+1]) j++; } 然而AC自动机既然已经基于 \(trie\) 树结构,自然可以对于每个下一位字母的情况来匹配,这里我们分类讨论 ​ 如果已经存在同字母的节点,那么就是下一位节点,而它的 \(fail\) 就是上一个失配位置 \(fail\) 的这一个字母的后继节点 ​ 如果不存在,就是上一个失配位置 \(fail\) 的这一个字母的后继节点 (

C++:class

為{幸葍}努か 提交于 2019-11-29 19:16:04
class 类是C++的一个重要概念,也是面向对象的一个重要内容。类的行为类似结构体,但功能比结构体的更强大。类是定义该类对象的一个模板,它告诉我们,一个类应该具有什么内容。 声明、定义 类用关键字 class 声明、定义。 class LiF1; // 声明一个类 class LiF2 {}; // 声明并定义一个类 如果仅作声明,在声明之后定义之前,它是一个 不完全类型 ,这时只能定义指向该类型的指针或引用,可以声明但不能定义以该类型作为参数或返回值的函数。在类的名字出现之后,他就被认为是声明过的,因此, 可以在类内定义指向自身类型的指针或引用 。有时会遇到一些比较复杂的情形,就需要我们先声明一个类,随后再去完善定义。比如:我们需要一个类X包含一个指向类Y的指针,同时,类Y又包含一个类型为X的对象,实现如下: class X; class Y { X* x; }; class X { Y y; }; 成员 类内的数据称为类的 成员(member) ,成员包括 成员变量 和 成员函数 。成员变量定义类的 属性 ,成员函数定义类的 行为 。 成员变量 在类内声明的变量称为成员变量。成员变量可以是任何数据类型,甚至可以是指向自身类型的指针或引用。 成员函数 声明在类内部的函数称为 成员函数 。成员函数的本质也是普通函数

Hello World

瘦欲@ 提交于 2019-11-29 18:17:39
就这样开始吧,如果不记录点东西的话,就证明自己没有思考过,怎么会真的深刻理解一个东西,无论是技术或者什么,小宝,和你一起加油 算法精解 : 写了好几天这个Set相关的东西,今天终于在抄袭那个例子代码的情况下完成了,虽然比较波折,但是学到的东西还是有的,列举一下吧: 1.如果一个东西是用指针来表示的,那么可以是任何东西,如果再加上**,那就更神奇了 2.return 的地方一定要考虑清楚,比如说我这次出现问题的这个set_remove 函数,最后调用list_rem_next的时候并没有写return,事实证明,编译器这个sb完全看不出来 Coolshell : C语言结构体里的成员数组和指针 : 结构体中的成员: 所有的变量名会在编译的时候放到这些内存中去, 有一些什么栈内存区、堆内存区、静态内存区、常量内存区 【内存对齐】,一个老生常谈的问题 struct test{ int i; short c; char *p; char s[10]; }; int main(){ struct test *pt=NULL; printf ( "&s = %x\n" , pt->s); //姚锟注,上面的其实相当于&(pt->s),并没有解引用 printf ( "&i = %x\n" , &pt->i); //其他的几个就很常见了 printf ( "&c = %x\n" , &pt->c

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)

只谈情不闲聊 提交于 2019-11-29 18:03:25
The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门: https://nanti.jisuanke.com/t/41400 题意: 给你三个数组a,b,c,要你求有多少个三元组(i,j,k),使得 \[ \begin{array}{l}{\left|A_{i}-B_{j}\right| \leq C_{k}, \text { and }} \\ {\left|B_{j}-C_{k}\right| \leq A_{i}, \text { and }} \\ {\left|A_{i}-C_{k}\right| \leq B_{j}}\end{array} \] 题解: 上面的不等式经过化简,我们可以得到 我们需要求有多少个三元组,使得 \(A_i,B_j,C_k\) 可以组成一个三角形 这样组成三角形的题目类似于HDU4609 ( https://www.cnblogs.com/buerdepepeqi/p/11236100.html ) 但是不同的是 我们需要从三个数组中选择 所以这里就涉及到了选择重复的问题,我们考虑去重 假设拿a+b做一遍卷积,得到长度为a+b的木棍的数量, 我们假设 c是三角形的最长边,那么a,b,c三根木棍不能组成三角形的情况就是c的长度大于a+b的数量 我们枚举(a

Question on multiple inheritance, virtual base classes, and object size in C++

穿精又带淫゛_ 提交于 2019-11-29 17:43:10
问题 The following code prints 20, i.e. sizeof(z) is 20. #include <iostream.h> class Base { public: int a; }; class X:virtual public Base { public: int x; }; class Y:virtual public Base { public: int y; }; class Z:public X,public Y { }; int main() { Z z; cout << sizeof(z) <<endl; } Whereas if I don't use virtual base classes here, i.e. for the following code : sizeof(z) is 16. #include <iostream.h> class Base { public: int a; }; class X:public Base { public: int x; }; class Y:public Base { public:

C++ simple sizeof difference between char array and char pointer

我与影子孤独终老i 提交于 2019-11-29 17:39:48
char * test = "test"; cout << sizeof(test); char test2[] = "test"; cout << sizeof(test2); Running this on visual studio 2010, why is the output 45 ? Shouldn't test be a string literal and the sizeof a string literal be the number of character elements in the string literal including the terminating null character? test is a pointer to a string literal, not a string literal (a char[] ): the sizeof(char*) is 4 , relating to test the sizeof(char[5]) is 5 , relating to test2[] hence 45 is the output. The first one displays the size of the pointer, not the array. In the second case, you are

Sizeof() on a C++ array works in one function, but not in the other

对着背影说爱祢 提交于 2019-11-29 15:33:01
I'm trying to learn more about arrays since I'm new to programming. So I was playing with different parts of code and was trying to learn about three things, sizeof() . How do I find the length of an array, and also how do I put arrays into functions (as a parameter)? My code is: #include <iostream> using namespace std; void arrayprint(int inarray[]) { for (int n_i = 0 ; n_i < (sizeof(inarray) / sizeof(int)) ; n_i++) { cout << inarray[n_i] << endl; } } int main() { int n_array[5]; for (int n_i = 0 ; n_i < (sizeof(n_array) / sizeof(int)) ; n_i++ ) { cin >> n_array[n_i]; } arrayprint(n_array);

why does the array decay to a pointer in a template function

百般思念 提交于 2019-11-29 15:09:38
问题 I don't understand why the array decays to a pointer in a template function. If you look at the following code: When the parameter is forced to be a reference (function f1) it does not decay. In the other function f it decays. Why is the type of T in function f not const char (buff&)[3] but rather const char* (if I understand it correctly)? #include <iostream> template <class T> void f(T buff) { std::cout << "f:buff size:" << sizeof(buff) << std::endl; //prints 4 } template <class T> void f1