小编onl*_*man的帖子

在C/C++上,基本上什么是编译器依赖的东西?

什么任务,功能,执行因编译器而异?我知道这段代码依赖于编译器 -

#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)

因此执行顺序因编译器而异.这些模棱两可的课程是否有资格参加考试?

c c++ compiler-construction

1
推荐指数
1
解决办法
3211
查看次数

执行顺序,静态块,字段

我知道静态块在任何事情之前运行.但是在这里,当调用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)

java static block

0
推荐指数
1
解决办法
1359
查看次数

数组作为方法参数

我们声明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)

java arrays arguments

0
推荐指数
1
解决办法
147
查看次数

我看到了这个节目.这是什么 - 在构造函数复数(double r,double i)之后的re(r),im(i){}?

// 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)

c++ syntax

-4
推荐指数
1
解决办法
377
查看次数

类中新类的对象

在Java或其他OOP语言中 -

class MyClass{
  int a=5;
  MyClass b=new MyClass();

  void mymeth()
  {
  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,在类中创建类的对象.当在里面创建新对象时,它将创建新成员和类对象(这里是b),这将再次创建成员,对象?这不会导致链条导致无限的对象和变量吗?愚蠢的查询.

java class object

-4
推荐指数
1
解决办法
209
查看次数

标签 统计

java ×3

c++ ×2

arguments ×1

arrays ×1

block ×1

c ×1

class ×1

compiler-construction ×1

object ×1

static ×1

syntax ×1