初始化数组sbox时,出现语法错误。请帮帮我。
reg [7:0] sbox[15:0];
sbox = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
Run Code Online (Sandbox Code Playgroud)
这实际上是sbox。显示的错误:
在“ =”附近:语法错误,意外的'=',期望IDENTIFIER或TYPE_IDENTIFIER
我正在使用modelsim模拟器
我有一个接收变量int的方法.该变量构成一个数组大小(请不要给我一个向量).因此,我需要在我的方法中初始化一个const int来初始化一个特定大小的数组.问题:我该怎么做?
void foo(int variable_int){
int a[variable_int] = {0}; //error
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Visual c ++编写c语言.
编译器给出了以下代码的错误:
#define SIZE 3;
int myMatrix[SIZE][SIZE];
void funcMatrix(int M[SIZE][SIZE]);
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
error C2143: syntax error : missing ']' before ';'
error C2059: syntax error : ']'
Run Code Online (Sandbox Code Playgroud)
我试过在主要和外部内部以不同方式声明常量.它仍然无法正常工作.如果有人可以帮助我,真的很感激...
我刚刚开始学习C#并使用Tutorials Point它来做这件事.在关于数组的部分中,我一直看到数组被声明为
string[] sarray = { "Hello", "From", "Tutorials", "Point" };
Run Code Online (Sandbox Code Playgroud)
或者像这样的其他时间:
int [] marks = new int[5] { 99, 98, 92, 97, 95 };
Run Code Online (Sandbox Code Playgroud)
来自c ++,第一种声明方法对我来说并不是全新的,但第二种方法是我不理解的方法.问题是如果数组将动态初始化,那么为什么使用大括号括起初始化列表来指定数组的内容?
按照它的方式初始化第二个是否有优势?
这里有一个有两个私有字段x和y的类;
class Point
{
private:
int x, y;
public:
Point(int = 1,int = 1);
void move(int, int);
void print()
{
cout << "X = " << x << ", Y = " << y << endl;
}
};
Run Code Online (Sandbox Code Playgroud)
初始化Point对象数组时,输出正常;
Point array1[] = { (10), (20), { 30, 40 } };
Run Code Online (Sandbox Code Playgroud)
输出;
First array
X = 10, Y = 1
X = 20, Y = 1
X = 30, Y = 40
Run Code Online (Sandbox Code Playgroud)
但是,如果我们按如下所示初始化Point数组,则输出很奇怪;
Point array2[] = { (10), (20), (30, 40) …Run Code Online (Sandbox Code Playgroud) c++ arrays initialization array-initialization object-initialization
我想知道是否有适当的方法可以做到这一点。
举个例子:
struct Test {
static std::array<unsigned, 123> data;
};
std::array<unsigned, 123> Test::data = {};
Run Code Online (Sandbox Code Playgroud)
如果我想将 中的所有元素设置为data某个值,例如 5。
我可以做这样的事情:
struct Test {
static std::array<unsigned, 123> data;
private:
static decltype(data) init_data_arr() {
decltype(data) arr = {};
arr.fill(5);
return arr;
}
};
std::array<unsigned, 123> Test::data = Test::init_data_arr();
Run Code Online (Sandbox Code Playgroud)
但随后我会分配额外的数组内存并对其进行复制,这似乎并不理想。
另一种内存密集程度较低的选项是这样的:
struct Test {
static bool is_init;
static std::array<unsigned, 123> data;
Test() {
if (!is_init) {
is_init = true;
data.fill(5);
}
}
};
bool Test::is_init = false;
std::array<unsigned, 123> Test::data = {}; …Run Code Online (Sandbox Code Playgroud) 所以我正在学习使用编译器Dev C++编程c.问题1:
#include <stdio.h>
#include <conio.h> //for the getch() function
#include <string.h>
int main(void)
{
char line[3];
strcpy(line, "Hello world");
printf("%s", line);
getch();
}
Run Code Online (Sandbox Code Playgroud)
输出:Hello world
为什么当我声明我的字符串只能容纳3个字符时,它会显示所有"Hello world"?
问题2:
char line[3] = "Hello world";
printf("%s", line);
Run Code Online (Sandbox Code Playgroud)
输出:Hel
为什么显示"Hel"?它不应该只显示"He",因为行[0] = H,行[1] = e和行[2] ='\ 0'?%s通过搜索'\ 0'来工作?
请帮我理解真正发生的事情.谢谢!
我需要帮助来理解如何在 Java 中初始化类的对象。
我的代码是这样的:
...
Test t[] = null;
...
for (i=0;i<20;i++)
t[i] = new Test(10,20);
...
Run Code Online (Sandbox Code Playgroud)
当我在 Eclipse 中编写上面的代码时,它给了我一个错误,说“空指针访问:变量数据在这个位置只能为空”。
我尝试了所有纠正错误的方法,但没有运气。
我的代码中存在什么语言语法问题?我想声明一个队列数组。这是声明和使用它们的正确方法吗?
public static void Main(string[] args)
{
Queue<int>[] downBoolArray = new Queue<int>[8]();
downBoolArray[0].Enqueue(1);
}
Run Code Online (Sandbox Code Playgroud)