考虑到C中函数内部的局部变量一旦被调用就会被压入堆栈(在压入传递给函数的变量之后),在堆栈缓冲区溢出之前,所述变量的数量是否有限制?或者该限制仅由确定的主机拥有的 RAM 量决定?
我尝试通过创建一个 4,6gb .C 文件来测试这一点,其中包含一个函数,该函数声明了 25000*13 个变量并将其初始化为 0。该函数在内部调用,main()但它编译得很好(使用 -O0)并且没有'崩溃。
我通常在几乎所有 VBA 代码中看到所有变量都在例如子/函数名称行之后声明
我知道并且我在一些代码中间使用了变量声明(不在循环内)并且没有看到任何问题。
我通常会避免这样做,因为我看到大多数 VBA 示例代码都在第一行之后声明了它们。我只是想知道从专家/经验丰富的 VB 程序员的角度来看有哪些风险。
我是C++的新手,这是我第一次使用它的类,我想知道,我如何调用构造函数?我已经阅读了一些关于C++课程的文档,这就是我想出的东西.构造函数调用私有方法来设置服务器.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sstream>
#include <string>
#include "SimpleIni.h"
#include "MySQL.cpp"
#include <thread>
class LoginServer {
int resSocket;
MySQL mysql;
struct sockaddr_in strctAddr;
private:
void log(std::string strText, std::string strType = "INFO"){
time_t rawtime;
struct tm * timeinfo;
char buffer[50];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 50, "%c",timeinfo);
std::cout << "[" << buffer << "][" << strType << "] > " << strText << std::endl;
} …Run Code Online (Sandbox Code Playgroud) c++ syntax constructor variable-declaration most-vexing-parse
为什么你必须@interface像这样在括号内声明变量?
@interface myClass : UIViewController {
NSString *myString;
IBOutlet UILabel *myLabel;
}
Run Code Online (Sandbox Code Playgroud)
为什么不在这里呢?
@interface myClass : UIViewController {
IBOutlet UILabel *myLabel;
}
NSString *myString;
Run Code Online (Sandbox Code Playgroud) scope global-variables objective-c instance-variables variable-declaration
虽然你可以使用变量而不在javascript中声明它,但是滥用变量会导致难以解决的错误.例如,以下代码将导致无限循环.
for(i=0;i<100;i++){
document.write(fiveTimes(i));
}
...
function fiveTimes(x){
i=5;
return (i*x);
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法强制在使用之前声明javascript中的每个变量.或者任何人都知道如何在庞大的Web服务器中检查大量的javascript文件和块之前的变量声明.
我多次听说过,如果你没有初始化变量,那么garbage value就存储在变量中.
说
int i;
printf("%d",i);
Run Code Online (Sandbox Code Playgroud)
上面的代码打印任何垃圾值,但我想知道如果未初始化,存储垃圾值需要什么?
Go文档表明应该使用速记:
x := "Hello World"
Run Code Online (Sandbox Code Playgroud)
而不是长形式
var x string = "Hello World"
Run Code Online (Sandbox Code Playgroud)
提高可读性.虽然以下工作:
package main
import "fmt"
var x string = "Hello World"
func main() {
fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)
这不是:
package main
import "fmt"
x := "Hello World"
func main() {
fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)
并给出错误"函数体外的非声明语句".相反,我在函数中声明它:
package main
import "fmt"
func main() {
x := "Hello World"
fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)
然后它工作得很好.看来我只能在使用变量的函数中使用简写.是这样的吗?谁能告诉我为什么?
我有一个问题,我需要将一些变量声明为自然数.哪个是我应该用于应该是自然数的变量的propper基本类型?喜欢整数是int ...
这不是修复或其他问题.只想知道行为
#include <stdio.h>
extern int var;
int main()
{
var = 10;
printf("%d ", var);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在这里我们可以看到,var定义为函数extern内部和定义.但是当输出时它出错了main()varvar
未定义的引用
var.
那么价值在10哪里?它会去extern var或存储在垃圾内存位置吗?
那么在编译行var =10和下一行时到底发生了什么.
编译日志:
Compilation error time: 0 memory: 2156 signal:0
/home/PpnviQ/ccRtZapf.o: In function `main':
prog.c:(.text.startup+0x13): undefined reference to `var'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 根据 C++: 在c ++中不允许创建一个用户输入的大小来创建具有运行时边界的数组.
但是我得到的代码编译没有错误.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin>>n;
int a[n][n];
a[n-1][n-1]=9;
cout<<a[n-1][n-1]<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它也很好用.在这里查看 - > http://cpp.sh/6bies
有人可以帮助解决这种混乱吗?