sizeof

【算法简述】图论专题:最短路

纵然是瞬间 提交于 2019-11-30 10:52:58
图论问题概述总结 对于**图论**,我们尊熟悉的算法是比较多的,这次,我就找了集中常用的算法。 ## 几种算法 1. **最短路**算法(Dijkstra,SPFE,FLOYD) - Dijkstra单源最短算法 首先,此算法适用于计算一个点到另一个点的最短路径,且算法绝对不能出现负环。这个算法的速度慢,只用于接觉小规模的问题,如图: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190609113100303.png)这个图就是求算法的基本思路。算法过程: - 从节点上找到最近点那个节点,将他标记,加入集合U。 - 将定点U连出边的邻点相连接,不在集合U中寻找。 - 重复前面的操作,用来指导V=U是,查找结束,最后结束流程。 本算法的算法流程图: https://wenku.baidu.com/view/8a5c11303968011ca300916a.html 参考代码: ``` #include <iostream> #include <cstring> using namespace std; const int N = 1e3 + 9; const int M = 1e4 + 9; const int inf = 0x3f3f3f3f; struct edge { int v, w, next; edge() {} edge(int

Sizeof doesn't return the true size of variable in C

大兔子大兔子 提交于 2019-11-30 10:00:11
问题 Consider the following code #include <stdio.h> void print(char string[]){ printf("%s:%d\n",string,sizeof(string)); } int main(){ char string[] = "Hello World"; print(string); } and the output is Hello World:4 So what's wrong with that ? 回答1: It does return the true size of the "variable" (really, the parameter to the function). The problem is that this is not of the type you think it is. char string[] , as a parameter to a function, is equivalent to char* string . You get a result of 4

JVM 对象查询语言(OQL)[转载]

核能气质少年 提交于 2019-11-30 09:55:56
最近生产环境出现一个很奇怪的问题,测试环境无法重现,本地直连生产无法重现。于是用上 jmap + Java VisualVM 的 OQL (Object Query Language) 分析问题。 关于OGL的文章不多,特此转载,原文出处: https://blog.csdn.net/pange1991/article/details/82023771 本文主要翻译自JDK 1.8的JVM监控工具jhat中关于OQL的英文帮助说明。 可以在jhat 和 jvisualvm 中进行实践。 OQL(对象查询语言) OQL是用于查询Java堆的类SQL查询语言。OQL允许过滤/选择从Java堆中获取的信息。虽然HAT已经支持预定义的查询,例如“显示类X的所有实例”,但OQL增加了更多的灵活性。OQL基于JavaScript表达式语言。 OQL查询的形式 select <JavaScript expression to select> [ from [instanceof] <class name> <identifier> [ where <JavaScript boolean expression to filter> ] ] 解释: (1)class name是java类的完全限定名,如:java.lang.String, java.util.ArrayList, [C是char数组

Potential problem with C standard malloc'ing chars

我是研究僧i 提交于 2019-11-30 09:32:44
When answering a comment to another answer of mine here , I found what I think may be a hole in the C standard (c1x, I haven't checked the earlier ones and yes, I know it's incredibly unlikely that I alone among all the planet's inhabitants have found a bug in the standard). Information follows: Section 6.5.3.4 ("The sizeof operator") para 2 states "The sizeof operator yields the size (in bytes) of its operand" . Para 3 of that section states: "When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1" . Section 7.20.3.3

sizeof continues to return 4 instead of actual size

拜拜、爱过 提交于 2019-11-30 09:20:50
问题 #include <iostream> using namespace std; int main() { cout << "Do you need to encrypt or decrypt?" << endl; string message; getline(cin, message); int letter2number; for (int place = 1; place < sizeof(message); place++) { letter2number = static_cast<int>(message[place]); cout << letter2number << endl; } } Examples of problem: I type fifteen letters but only four integers are printed. I type seven letters but only four integers are printed. The loop only occurs four times on my computer, not

C++ Size of Array [duplicate]

社会主义新天地 提交于 2019-11-30 09:14:59
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Sizeof array passed as parameter I am being stupid with this sizeof operator in c++, do you have any idea why it is 4 and 12 ? void function (int arg[]) { cout<<sizeof(arg)<<endl; // 4 } int main () { int array[] = {1, 2, 3}; cout<<sizeof array<<endl; // 12 function (array); return 0; } 回答1: In main , the name array is an array so you get the size in bytes of the array with sizeof . However, an array decays to a

why sizeof(13.33) is 8 bytes?

可紊 提交于 2019-11-30 08:59:40
问题 When I give sizeof(a) , where a=13.33 , a float variable, the size is 4 bytes. But if i give sizeof(13.33) directly, the size is 8 bytes. I do not understand what is happening. Can someone help? 回答1: Those are the rules of the language. 13.33 is a numeric literal. It is treated as a double because it is a double. If you want 13.33 to be treated as a float literal, then you state 13.33f. 13.33 is a double literal. If sizeof(float) == 4, sizeof(13.33f) == 4 should also hold because 13.33f is a

9.23笔试总结

一笑奈何 提交于 2019-11-30 08:37:25
C语言的一些小东西,长时间没用忘得差不多了: #include<iostream> using namespace std; int main() { int m = 5; int n = 6; n += n -=m *= n; cout <<"n:"<< n<<endl; int k = 0; char a; char b[] = "hello"; char* p = b; cout << "a:"<<sizeof(a)<<"b:"<<sizeof(b)<<"c:"<<sizeof(p); return 0; += -= *=这类是从右往左 char类型的指针,sizeof()结果是4,sizeof一个长度为5的字符数组"hello" 结果是6,因为到“\0”结束 循环赋值,这样写没错。 来源: https://www.cnblogs.com/xingzhuan/p/11576070.html

Can “sizeof(arr[0])” lead to undefined behavior?

瘦欲@ 提交于 2019-11-30 08:25:11
There is a well known pattern of figuring out array length: int arr[10]; size_t len = sizeof(arr) / sizeof(arr[0]); assert(len == 10); This pattern applies to static arrays and auto arrays of constant size. It also applies to variable length arrays in C99. I want to apply similar idea for figuring out dynamic array size in bytes: size_t known_len = 10; int *ptr = malloc(known_len * sizeof(int)); size_t size = known_len * sizeof(ptr[0]); assert(size == known_len * sizeof(int)); This is nicer than known_len * sizeof(int) because sizeof(ptr[0]) doesn't refer to actual array element type. Hence it

Pointer implementation details in C

百般思念 提交于 2019-11-30 06:40:36
I would like to know architectures which violate the assumptions I've listed below. Also, I would like to know if any of the assumptions are false for all architectures (that is, if any of them are just completely wrong). sizeof(int *) == sizeof(char *) == sizeof(void *) == sizeof(func_ptr *) The in-memory representation of all pointers for a given architecture is the same regardless of the data type pointed to. The in-memory representation of a pointer is the same as an integer of the same bit length as the architecture. Multiplication and division of pointer data types are only forbidden by