什么任务,功能,执行因编译器而异?我知道这段代码依赖于编译器 -
#include <stdio.h>
#define PRODUCT(x)(x*x)
int main()
{
int i=3,j,k;
j=PRODUCT(i++);
k=PRODUCT(++i);
printf("\n%d %d",j,k);
}
Run Code Online (Sandbox Code Playgroud)
下面给出了一些垃圾,而其他的则是固定值 -
#include <stdio.h>
int main()
{
int i=5,j=10;
printf("%d,%d");
}
Run Code Online (Sandbox Code Playgroud)
因此执行顺序因编译器而异.这些模棱两可的课程是否有资格参加考试?
我知道静态块在任何事情之前运行.但是在这里,当调用B.test()时会发生什么?执行顺序和值的设定?后来,当b1设置为null时,b1.i如何计算为20?
class B
{
static int i;
static {
i = 20;
System.out.println("SIB");
}
static int test() {
int i = 24;
System.out.println(i);
return i;
}
}
public class Manager {
public static void main(String[] arg) {
B.test();
B b1 = null;
System.out.println(b1.i);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
SIB
24
20
Run Code Online (Sandbox Code Playgroud) 我们声明String数组像 -
String[] a={"A"};
Run Code Online (Sandbox Code Playgroud)
但是当一个方法将String数组作为参数时,为什么我们不能像以下那样调用方法?
mymethod({"A"});
Run Code Online (Sandbox Code Playgroud)
码-
class A{
static void m1(String[] a) { }
public static void main(String args[]){
m1(new String []{});//OK
m1({}); //Error
}
}
Run Code Online (Sandbox Code Playgroud) // operator_overloading.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
struct Complex {
Complex( double r, double i ) : re(r), im(i) {} // what is this syntax?
Complex operator+( Complex &other );
void Display( ) { cout << re << ", " << im << endl; }
private:
double re, im;
};
// Operator overloaded using a member function
Complex Complex::operator+( Complex &other ) {
return Complex( re + other.re, im + other.im );
}
int main() { …Run Code Online (Sandbox Code Playgroud) 在Java或其他OOP语言中 -
class MyClass{
int a=5;
MyClass b=new MyClass();
void mymeth()
{
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,在类中创建类的对象.当在里面创建新对象时,它将创建新成员和类对象(这里是b),这将再次创建成员,对象?这不会导致链条导致无限的对象和变量吗?愚蠢的查询.