#include <stdio.h>
int main()
{
int *p = (int*) 60; --- Line 1
int *q = (int*) 40; --- Line 2
printf("%d", p-q); //Output is 5
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释一下这个程序的输出吗?
以下代码工作正常:
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct node{
int a, b, c, d, e;
};
struct node *ptr = NULL;
printf("Size of pointer ptr is %lu bytes\n",sizeof (ptr));
printf("Size of struct node is %lu bytes\n",sizeof (struct node));
ptr = (struct node*)malloc(sizeof (ptr)); //Line 1
// ptr = (struct node*)malloc(sizeof (struct node)); //Line 2
ptr->a = 1; ptr->b = 2; ptr->c = 3; ptr->d = 4; ptr->e = 5;
printf("a: %d, b: %d, c: %d, d: %d, e: %d\n", …Run Code Online (Sandbox Code Playgroud) 什么是程序的输出
#include <stdio.h>
int fun(char *a){
printf("%d\n",sizeof(a));
return 1;
}
int main(){
char a[20];
printf("%d\n",sizeof (fun(a)));
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个定向的未加权图.给出了节点数和节点之间的所有链路.我尝试使用向量数组执行任务,但java不支持它.ArrayList和Vectors支持随机访问迭代器但不能在java中执行它,因为我是新手.我不想使用二维矩阵.我想将它实现为N个给定节点的数组,其中每个节点都有一个连接到它的节点的列表.请有人提供伪代码或任何可以帮助我的东西.例如,图表给出为
5
3 4
4 2
1 5
4 3
1 3
2 5
Run Code Online (Sandbox Code Playgroud)
这里给出了5个编号为1到5的节点.以下是从第一个节点到第二个节点的有向边.我想将其表示为图的邻接列表.任何人都可以实施吗?
删除给定行的注释后,我在代码中编译错误.我无法将结构插入到地图中,而插入整数很好.如何修复错误?
# include <iostream>
# include <map>
using namespace std;
struct node
{int test;} temp;
int main()
{
temp.test = 24;
int test = 30;
map<node, bool> mymap1;
map<int, bool> mymap2;
//mymap1.insert(make_pair(temp, true));
mymap2.insert(make_pair(test, true));
return 0;
}
Run Code Online (Sandbox Code Playgroud) 以下代码1没问题
#include <stdio.h> // code 1
main()
{
printf("%u",main);
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码2给出了分段错误.
#include <stdio.h> // code 2
main()
{
printf("%u",main());
}
Run Code Online (Sandbox Code Playgroud)
我没有得到main和main()之间的区别?
下面的代码显示了mixin。
trait A{
def a = 1
}
trait X extends A{
override def a = {
println("X")
println((super.a + 3).toString)
super.a + 3
}
}
trait Y extends A{
override def a = {
println("Y")
println((super.a + 5).toString)
super.a + 5
}
}
val xy = new AnyRef with X with Y
xy.a
Run Code Online (Sandbox Code Playgroud)
代码的输出是
Y
X
4
9
X
4
Run Code Online (Sandbox Code Playgroud)
我已经读过混合两个或多个特征的用法,显示从最右边到最左边开始的可堆叠行为,并使用线性化解决了对super()的调用。但是从输出来看,似乎X被调用了两次。请解释输出。