我想知道数组如何在c中工作.我最终得出一个假设,我想知道我是否正确.
我们知道数组是一系列相邻的内存盒(盒子),其中每个盒子的大小都是它所存储的类型(即如果INT的一个盒子的大小= sizeof(int),则一个3个INT的数组占用内存相邻的位置3 sizeof(int))
现在我们也知道我们可以为某种类型的数组动态分配内存(C中的malloc,C++中的new).
让我想知道的是,当使用括号[0]调用数组时,数组的第一个数据框的地址和第一个值(后面的框中的值)是数组[0] = =*(数组+ 0)==*数组(数组是否被声明为"type*array"或"type array []"或"type array [size]")和"数组"这样称为无论是定义为指针还是数组("type*array"或"type array []"或"type array [size]")是第一个框的地址.
我最后想到了,我想要对此进行确认:数组甚至用方括号([]声明)实际上在内存中是一系列n个指针,每个指针包含(具有不作为地址的值)的地址包含实际值的存储器盒Bi +那些包含实际值的存储器盒(B0,...,Bn).这样,当一个人声明"int array [5]"时,程序实际上分配了5个相邻的int指针框P0,P1,...,P4和5个整数计算机存储器B0,B1的内部存储器位置. ..,B4,其中Pi的值是Bi的地址

我是对还是错!! 谢谢!
我有这个令人困惑的代码:
public class Confusing {
private Confusing(Object o){
System.out.println("Object");
}
private Confusing(double[]dArray){
System.out.println("double array");
}
public static void main(String[] args){
new Confusing(null);
}
}
Run Code Online (Sandbox Code Playgroud)
当"编译"并运行程序显示"双数组"为什么数组先于Object?是否有其他构造函数情况会发生这种令人困惑的行为?
我正在尝试制作一个 api,它会在数据库中创建该单词后返回该单词的类型(名词、代词、动词等)。但是由于某种原因,当我的词汇模型中明确定义了类型方法时,我收到了“调用未定义的方法 Illuminate\Database\Eloquent\Relations\BelongsTo::type()”错误。我没有使用多对多的关系,而是使用一对多的关系(这就是我使用 hasMany() 和belongsTo 的原因)。Type 有很多 Vocabulary 但是 Vocabulary 只有一个 Type 和很多 VocabularyContents 并且 VocabularyContent 只有一个相关的词汇。所以显然没有多对多的关系。很明显,我的问题不是Call to undefined method (laravel 5.2) 的重复。以下是该应用程序的部分代码。
第一个模型是类型模型,它允许我获取类型的“内容”(此处未列出模型)和属于特定类型的词汇表。
模型代码清单 1:VocType.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class VocType extends Model
{
public function contents()
{
return $this->hasMany('App\VocTypeContent');
}
public function vocabularies()
{
return $this->hasMany('App\VocVocabulary');
}
}
Run Code Online (Sandbox Code Playgroud)
这第二个模型允许我在词汇表中创建一个词,访问它的“内容”、类型和类别。这就是问题所在。
模型代码清单 2:VocVocabulary.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class VocVocabulary extends Model
{
protected $fillable = ['voc_category_id','type_id', 'name', 'context', 'picture'];
public $timestamps = false;
public function contents()
{ …Run Code Online (Sandbox Code Playgroud) 我想在C中创建一个函数,它将为函数参数中的指针动态分配内存.
#include <stdio.h>
#include <stdlib.h>
int allocate(char * arr, int size){
int code = -1;
arr = malloc(size);
if(arr != NULL) code = size;
return code;
}
void main(){
char * array;
if(allocate(array,4) != -1){
printf("allocated!\n");
if(array == NULL) printf("Oops it actually didn't allocate!\n");
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行程序时; 它只会显示"已分配!" 和"哎呀它实际上没有分配!".这意味着内存分配确实发生了(因为函数的返回码不是-1.但是当我检查数组是否等于NULL时;它实际上是!
这是一个我已经遇到的编程问题,遗憾的是在某些情况下我无法使用像这样的char*allocate(char*arr,int size); 并将返回值赋给char*数组.
我正在编写一些代码。JFrame包含JPanel具有特定尺寸的。这是我的代码:
import javax.swing.*;
import java.awt.*;
public class ScrollPane extends JFrame {
public ScrollPane() {
super("Title");
setLayout(new BorderLayout());
setSize(320,240);
JScrollPane scroller = new JScrollPane(new DrawingPane());
scroller.setPreferredSize(new Dimension(320,240));
add(scroller);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private class DrawingPane extends JPanel {
public DrawingPane(){
super();
setSize(640,480);
setMinimumSize(new Dimension(320,240));
}
}
public static void main(String[] args) {
new ScrollPane();
}
}
Run Code Online (Sandbox Code Playgroud)
即使设置了最小尺寸JPanel,卷轴也不会出现。