struct x
{
char b;
short s;
char bb;
};
int main()
{
printf("%d",sizeof(struct x));
}
Run Code Online (Sandbox Code Playgroud)
输出为:6
我在32位编译器上运行此代码.输出应该是8个字节.
我的解释 - > 1. Char需要1个字节,下一个short需要2的倍数,所以short创建1的填充并占用2个字节,这里已经分配了4个字节.现在唯一的左边的char成员需要1个字节但是因为内存分配是4的倍数所以总内存给出的是8个字节.
我不太了解 C 编程指针,我尝试在互联网上搜索有关使用与结构相关的简单指针的信息。我有这个简单的程序:
#include <stdio.h>
typedef struct
{
int ia;
int ib;
} num;
int main()
{
num *pn;
//int a = 4;
pn->ia = 5;
printf("Hello, I made it this far!\n");
pn->ib = 10;
pn->ia = pn->ib;
printf("num = %d\n", pn->ia);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我取消注释未使用的整数 'int a = 4;' 之前,此代码不起作用
我在 Windows 10 上使用 gcc 32 位还是 64 位似乎无关紧要。
我想学习以正确的方式做到这一点,我不相信一个未使用的变量应该使它起作用!
为什么是这样:
http://MySite.com/Project/24/Search/32/Edit/49
Run Code Online (Sandbox Code Playgroud)
比这更受欢迎?
http://MySite.com/Project/24?Search=32&Edit=49
Run Code Online (Sandbox Code Playgroud) 我有一个关于转换的菜鸟问题.
string Descript1 = ":1:2:3:4:5";
Regex pattern = new Regex("(:)");
foreach (string sub in pattern.Split(Descript1))
{
if (sub != ":")
{
float a = Convert.ToSingle(sub);
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码不断提出错误:"字符串的格式不正确."
有人可以帮帮我吗?
谢谢.
我正在尝试创建一个适用于列表的数组实现的remove方法.我可以将duplicate元素设置为null以将其删除吗?假设列表是有序的.
ArrayList a = new ArrayList[];
public void removeduplicates(){
for(a[i].equals(a[i+1]){
a[i+1] = null;
}
a[i+1] = a[i];
}
Run Code Online (Sandbox Code Playgroud) 我找到了一个算法Package-Merge
Algorithm(I, X) {
S is empty;
for all d, Ld list of items having width 2^d;
while X > 0 loop
minwidth = the smallest term in diadic expansion of X;
if I=0 then //is empty
return “No solution.” ;
else
d=the minimum such that L is not empty;
r=2^d;
if r > minwidth then
return “No solution.”
else if r = minwidth then
Delete the minimum weight ;
X= X - minwidth ;
end if
Pd+1=PACKAGE(Ld) ; …Run Code Online (Sandbox Code Playgroud) 我正在尝试用C#编写一个简单的Lambda表达式:
int numElements = 3;
string[]firstnames = {"Dave", "Jim", "Rob"};
string[]lastnames = {"Davidson", "Jameson", "Robertson"};
List<Person> people = new List<Person>();
for(int i = 0 ; i < numElements; i++)
{
people.Add(new Person { FirstName = firstnames[i], LastName = lastnames[i] });
}
bool test = people.Contains(p => p.FirstName == "Bob");
Run Code Online (Sandbox Code Playgroud)
我对Lambda表达式以及它们如何工作的理解仍然有点阴暗,我对于为什么这不起作用我很恼火......我试图找出一个列表是否包含一个名字......
我在我的应用程序中使用内置设置和Im阅读设置以这种方式
variable = (bool)Settings.Default["GetHKAlt"];
Run Code Online (Sandbox Code Playgroud)
并以这种方式保存:
Settings.Default["GetHKAlt"] = variable;
Run Code Online (Sandbox Code Playgroud)
但是在我在运行时修改设置并关闭我的应用程序后,这些设置都消失了,这个网站说这个设置保存在app.config文件中,但是我在任何地方都看不到这个文件
import javax.swing.*;
public class Main {
public static void main(String[] args) {
int r=0,c=0;
String input,inputt;
input = JOptionPane.showInputDialog("Plz Enter the number of Rows");
r = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Plz Enter the number of Coloms");
c = Integer.parseInt(input);
int array[][]= new int[r][c];
for (int i=0;i<=r;i++)
{
for (int j=0;j<=c;j++)
input = JOptionPane.showInputDialog("Plz Enter the elemet of the array");
array [r][c]= Integer.parseInt(input);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用JOption声明2d数组