小编use*_*138的帖子

c#中的int是什么?

什么是intC#?它是一个关键字,还是从system.ValueTypes派生的类?如果它是关键字,那么以下行如何编译

int i = new int(); // If int is not a class then how does it have a default constructor

Console.WriteLine(i.ToString()); // If int is not a class then how does it have member functions
Run Code Online (Sandbox Code Playgroud)

如果int是一个类,为什么没有必要总是用它初始化它new?以下行如何编译?

int i = 8;
Run Code Online (Sandbox Code Playgroud)

c# value-type reference-type

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

了解synchronized关键字的工作原理

在下面的代码中,我只希望两个线程中的一个进入该halt()函数,然后暂停程序.但似乎两个线程都进入了synchronizedhalt()函数.为什么会发生这种情况?

package practice;

class NewThread implements Runnable {
  String name; // name of thread
  Thread t;
  boolean suspendFlag;

  NewThread(String threadname) {
    name = threadname;
    t = new Thread(this, name);
    System.out.println("New thread: " + t);
    suspendFlag = false;
    t.start(); // Start the thread
  }

  // This is the entry point for thread.
  public void run() {
    try {
      for(int i = 15; i > 0; i--) {
        System.out.println(name + ": " + i);
        Thread.sleep(200);
        Runtime r = …
Run Code Online (Sandbox Code Playgroud)

java synchronized

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

矢量元素似乎不是有条理地存储的

为什么上一个预期输出与以下代码中的实际输出不同?

#include<iostream>
#include<fstream>
#include<istream>
#include<sstream>
#include<vector>

using namespace std;


int main()
{
        vector<int> v;
        for(int ii = 0; ii < 4; ii++){
            v.push_back(0);
        }

        vector<vector<int>> twoDv;

        for(int ii = 0; ii < 5; ii++){
            twoDv.push_back(v);
        }

        cout<<"Expected Output : " << &twoDv[0][0] <<'\t'<< (&twoDv[0][0] + 3) <<'\t'<< (&twoDv[0][3] + 1)<<'\n';
        cout<<"Actual Output   : " << &twoDv[0][0] <<'\t'<< &twoDv[0][3] <<'\t'<< &twoDv[1][0] << '\n';
}
Run Code Online (Sandbox Code Playgroud)

c++ vector

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

将const ref分配给非const对象

在下面的代码中,我们返回一个const对象并将其收集在非const对象中,并且它仍然可以编译而不会出现错误或警告.

class foo
{
    int i;
public:
    const foo& call() const
    {
        return *this;
    }
};

int main()
{
    foo aa, bb;
    bb = aa.call();
}
Run Code Online (Sandbox Code Playgroud)

c++

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

模仿printf

以下代码有什么问题?我们如何使print()函数作为printf工作?

#include <stdio.h>
#include<stdarg.h>

void print(char *format,...)
{
    va_list args;
    va_start(args,format);
    printf(format,args);
}

int main() {
   print("%d %s",5,"le");
}
Run Code Online (Sandbox Code Playgroud)

c printf

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

标签 统计

c++ ×2

c ×1

c# ×1

java ×1

printf ×1

reference-type ×1

synchronized ×1

value-type ×1

vector ×1