这是我的代码:
public class Test
{
static
{
main(null);
}
public static void main(String [] args)
{
System.out.println("done");
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
done
done
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下这个原因吗?
谁能告诉我为什么我的SimpleTest应用程序不显示"测试"?DLL加载成功,我只是没有得到任何控制台输出.
SimpleDLL.cpp
#include "stdafx.h"
#include "SimpleDLL.h"
#include "stdafx.h"
#include <iostream>
int Test()
{
std::cout << "Test" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
SimpleDLL.h
#ifndef _DLL_TUTORIAL_H_
#define _DLL_TUTORIAL_H_
#include <iostream>
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
DECLDIR int Test();
#endif
Run Code Online (Sandbox Code Playgroud)
SimpleTest.cpp
#include "stdafx.h"
#include <iostream>
#include <windows.h>
typedef int (*TestFunc)();
int main()
{
TestFunc _TestFunc;
HINSTANCE hInstLibrary = LoadLibrary( _T("SimpleDLL.dll"));
if (hInstLibrary)
{
_TestFunc = (TestFunc)GetProcAddress(hInstLibrary, "Test");
}
else
{
std::cout << "DLL Failed To Load!" << …
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的猜谜游戏程序.我的问题是,一旦用户输入错误的数字,我不确定如何将程序循环回程序的开头.我希望程序继续向用户询问一个数字,直到他做对了.有人能帮我吗?
#include <stdio.h>
int main (void) {
int value = 58;
int guess;
printf("Please enter a value: ");
scanf("%i", &guess);
if (guess == value) {
printf("Congratulations, you guessed the right value");
}
else if (guess > value) {
printf("That value is too high. Please guess again: ");
scanf("%i", &guess);
}
else if (guess < value) {
printf("That value is too low. Please guess again: ");
scanf("%i", &guess);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我听说你每次使用"new"时都应该"删除",但是当我运行一个简单的测试程序(下面)时,我为arraySize或numLoops添加的数字似乎没什么区别.这会导致内存泄漏吗?
#include <iostream>
int main()
{
double *array;
const int arraySize = 100000;
const int numLoops = 100000;
for (int i = 0; i < numLoops; i++)
{
// do I need to call "delete [] array;" here?
array = new double[arraySize];
}
int x;
std::cin >> x; // pause the program to view memory consumption
delete [] array;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 如何使用函数的参数在函数内声明一个数组?
我的代码是:
double function_2(int a)
{
int t[a];
}
Run Code Online (Sandbox Code Playgroud)
发生错误:
Expression must have a constant value.
Run Code Online (Sandbox Code Playgroud) 有多种的MaxProductOfThree任务答案codility.com,其中大部分涉及排序算法.
问题是:
给出了由N个整数组成的非空零索引数组A.
问题是找到给定数组中3个元素的最大乘积.
阵列的长度在3到100,000之间
数组A的每个元素都是[-1,000..1,000]范围内的整数
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(1),
Run Code Online (Sandbox Code Playgroud)
超出输入存储(不计入输入参数所需的存储).例:
a[0] = -3;
a[1] = 7;
a[2] = 2;
a[3] = 1;
a[4] = 5;
a[5] = 7;
Run Code Online (Sandbox Code Playgroud)
最大乘积是[1]*a [4]*a [5] = 245
除了涉及排序的O(n log n)方法之外,是否存在线性时间解决该问题的方法?
我re.findall(p, text)
一般用来匹配一个模式,但现在我遇到了一个问题:
我只想p
匹配普通字符串,而不是正则表达式.
例如:p可能包含'+'或'*',我不希望这些字符在正则表达式中具有特殊含义.换句话说,我希望p逐个字符匹配.
在这种情况下p
,我不知道,所以我不能在其中添加'\'来忽略特殊字符.
我刚刚在一个有意思的易受攻击的C程序中遇到了这段令人困惑的代码:
sscanf(user_input, "FOO;%.70s", buf);
Run Code Online (Sandbox Code Playgroud)
这个格式字符串有效吗?我尝试用它解析一些东西(即读取内容buf
,但它不起作用:
#include <string.h>
#include <stdio.h>
int main() {
char buf[100];
memset(buf, 0x41, sizeof buf);
// output: "FOO;asdasd\n"
printf("FOO;%.70s\n", "asdasd");
sscanf("FOO;asdasd", "FOO;%.70s", buf);
// output: 41 41 41 41 41 41 41 41 41 41
for (int i = 0; i< 10; ++i)
printf("%02x ", buf[i]);
puts("");
}
Run Code Online (Sandbox Code Playgroud)
我的主要问题是,如果我能够实际读取数据buf
使用它,甚至可能超过70个字节?但是,如果这是未定义的行为,在使用现代GCC编译和运行用户输入时,它是否会以某种方式直接导致内存损坏?
澄清:我知道这"FOO;%70s"
会奏效.但这根本不是问题.我不能修改这个程序.它是一个setuid二进制文件,我想利用它作为战争游戏的一部分来升级Linux机器上的权限.因此,我需要完全理解它的作用,特别是我是否可以buf
通过此sscanf
声明阅读内容.