sizeof

「题解」kuangbin 最小生成树

半世苍凉 提交于 2019-12-01 21:55:29
POJ-1251 Jungle Roads (水题,%c) POJ-1287 Networking (水) POJ-2031 Building a Space Station (%f浮点数尴尬精度,两球间距离) POJ-2421 Constructing Roads (一些边已建好,简单处理一下) ZOJ-1586 QS Network (处理一下边权) HDU-1233 还是畅通工程 (水) HDU-1875 畅通工程再续 (浮点数,条件连边) HDU-1301 Jungle Roads (重复 -> POJ-1251) POJ-2349 Arctic Network (第 K 大边) POJ-1751 Highways (求最小生成树的边,加 0 权边) UVA-10147 Highways (多组的 POJ-1751) + POJ-1258 Agri-Net (水) POJ-3026 Borg Maze (BFS + Kruskal,用最短路建图,垃圾输入) POJ-1789 Truck History (Prim,Kruskal 超时) POJ-1679 The Unique MST (次小生成树) 代码最后附简单题解 模板 Kruskal

linux 网络编程

帅比萌擦擦* 提交于 2019-12-01 21:49:14
int socket (int domain, int type, int protocol); 建立新的通信端口 int domain  网络层协议 可以填 AF_INET 表示IPv4 AF_INET6 表示IPv6 int type  传输类型 可以填 SOCK_STREAM 表示TCP SOCK_DGRAM 调试UDP int protocol  指定传输协议编号,这里填 0 返回值:成功→套接字文件描述符  失败→ -1 int serfd; serfd = socket(AF_INET,SOCK_STREAM,0); if(serfd == -1) { perror(“socket fail”); exit(-1); } int bind (int sockfd, const struct sockaddr *addr,socklen_t addrlen); 将服务器的地址信息与套接字进行绑定 int sockfd          套接字文件描述符 const struct sockaddr *addr  指向服务器地址信息的指针 struct sockaddr_in {   unsigned short int sin_family;  网络层协议对应的宏 AF_INET表示IPv4   uint16_t sin_port;        端口号   struct

Struct has different size if the field order is different

≡放荡痞女 提交于 2019-12-01 21:21:01
package main import ( "fmt" "unsafe" ) type A struct { a bool b int64 c int } type B struct { b int64 a bool c int } type C struct { } func main() { // output 24 fmt.Println(unsafe.Sizeof(A{})) // output 16 fmt.Println(unsafe.Sizeof(B{})) // output 0 fmt.Println(unsafe.Sizeof(C{})) } Struct A and B have the same fields, but if specified in different order they result in different size. why? Size of struct C is zero. How much memory is allocated by the system for a := C{} ? Thanks. 1. Struct sizes TL;DR; (Summary): Different implicit padding will be used if you reorder the fields, and the

$NOIp$做题记录

假如想象 提交于 2019-12-01 20:25:39
虽然去年做了挺多了也写了篇一句话题解了但一年过去也忘得差不多了$kk$ 所以重新来整理下$kk$ $2018$ [X] 积木大赛 大概讲下$O(n)$的数学方法. 我是从分治类比来的$QwQ$.考虑对每个点,如果它左侧比它高,显然可以在左侧被消的时候顺便把它消了. 否则只能消到左侧那个高度. 所以答案为$\sum max(0,a_i-a_{i-1})$ #include<bits/stdc++.h> using namespace std; #define il inline #define gc getchar() #define ri register int #define rb register bool #define rc register char #define rp(i,x,y) for(ri i=x;i<=y;++i) #define my(i,x,y) for(ri i=x;i>=y;--i) int n,nw,pre,as; il int read() { ri x=0;rb y=1;rc ch=gc; while(ch!='-' && (ch>'9' || ch<'0'))ch=gc; if(ch=='-')ch=gc,y=0; while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc; return

Output of using sizeof on a function [duplicate]

跟風遠走 提交于 2019-12-01 20:14:40
问题 This question already has answers here : what does sizeof (function name) return? (4 answers) Closed 5 years ago . Why does the following code give: #include<stdio.h> int voo() { printf ("Some Code"); return 0; } int main() { printf ("%zu", sizeof voo); return 0; } The following output: 1 回答1: The C language does not define sizeof for functions. The expression sizeof voo violates a constraint, and requires a diagnostic from any conforming C compiler. gcc implements pointer arithmetic on

Sizeof(char[]) in C

﹥>﹥吖頭↗ 提交于 2019-12-01 18:32:29
Consider this code: char name[]="123"; char name1[]="1234"; And this result The size of name (char[]):4 The size of name1 (char[]):5 Why the size of char[] is always plus one? As Michael pointed out in the comments the strings are terminated by a zero. So in memory the first string will look like this "123\0" where \0 is a single char and has the ASCII value 0. Then the above string has size 4. If you had not this terminating character, how would one know, where the string (or char[] for that matter) ends? Well, indeed one other way is to store the length somewhere. Some languages do that. C

Marshal.SizeOf structure returns excessive number

浪子不回头ぞ 提交于 2019-12-01 17:54:36
I have the following structure [StructLayout(LayoutKind.Sequential)] public struct SFHeader { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)] public string FileName; public int Offset; public short Size; public byte Flags; public byte Source; public long LastWriteTime; public byte[] GetBytes() { int size = Marshal.SizeOf(this); var buffer = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(this, ptr, true); Marshal.Copy(ptr, buffer, 0, size); Marshal.FreeHGlobal(ptr); return buffer; } public static SFHeader FromBytes(byte[] buffer) { var str = new SFHeader();

strlen和sizeof

只愿长相守 提交于 2019-12-01 17:36:51
sizeof是在编译的时候就将结果计算出来了是类型所占空间的字节数,所以以数组名做参数时计算的是整个数组的大小。而strlen是在运行的时候才开始计算结果,这是计算的结果不再是类型所占内存的大小,数组名就退化为指针了。 strlen(): 函数 strlen是寻找从指定地址开始,到出现的第一个0之间的字符个数 sizeof()运算符 sizeof https://blog.csdn.net/weixin_41042404/article/details/86719441 在本文中有很多是从 https://blog.csdn.net/weixin_41042404/article/details/86719441 搬运的,感谢该文的作者,大家转载别忘了附上该文链接。 以下是一个C程序,注释是对应的知识介绍 #include<stdio.h> #include<string> #include <stdlib.h> typedef long TLONG; int f1() { return 0; }; double f2() { return 0.0; } void f3() {} union u1//定义联合 { double a; int b; }; union u2 { char a[13]; int b; }; union u3 { char a[13]; char b; }

C memset seems to not write to every member

爱⌒轻易说出口 提交于 2019-12-01 17:33:17
I wrote a small coordinate class to handle both int and float coordinates. template <class T> class vector2 { public: vector2() { memset(this, 0, sizeof(this)); } T x; T y; }; Then in main() I do: vector2<int> v; But according to my MSVC debugger, only the x value is set to 0, the y value is untouched. Ive never used sizeof() in a template class before, could that be whats causing the trouble? No don't use memset -- it zeroes out the size of a pointer (4 bytes on my x86 Intel machine) bytes starting at the location pointed by this . This is a bad habit: you will also zero out virtual pointers

C零基础视频-29-对于字符串的sizeof与strlen的区别

最后都变了- 提交于 2019-12-01 17:22:12
目录 sizeof与strlen的不同表现 关于sizeof与strlen的对比总结 sizeof与strlen的不同表现 看程序说结果: #include <stdio.h> #include <string.h> int main(int argc, char* argv[]) { char* szHello = "Hello"; printf("%d\r\n", sizeof(szHello)); printf("%d\r\n", sizeof("Hello")); printf("%d\r\n", strlen(szHello)); return 0; } 关于sizeof与strlen的对比总结 sizeof是运算符,编译时求各种变量、类型大小,对字符串会包括结尾的'\0' strlen是函数,求字符串的长度,不包括结尾的'\0' 来源: https://www.cnblogs.com/shellmad/p/11695568.html