小编Lyr*_*yrk的帖子

为什么sizeof(array)和sizeof(&array [0])给出不同的结果?

#include <stdio.h>
int main(void){
    char array[20];

    printf( "\nSize of array is %d\n", sizeof(array) );  //outputs 20
    printf("\nSize of &array[0] is %d\n", sizeof(&array[0]); //output 4
}
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了20for sizeof(array)4for sizeof(&array[0]).

我所知道的不是将数组作为参数,而是可以传递它的第一个元素.他们不应该给出与20相同的输出吗?为什么&array[0]给出4作为结果?据我所知,char存储在1个字节中?

c sizeof

12
推荐指数
3
解决办法
1760
查看次数

在Eclipse中安装新的JRE之后,我的所有Java项目都会出错

我安装了旧版本的JRE,我的所有项目都开始出现编译器错误.(项目的"构建路径"上有一个交叉和(未绑定)消息)当我选中时,它们仍然会在路径中看到已卸载的JRE.我做了一些并逐一改变但是没有一种快速方法可以同时为我当前的所有项目添加新的JRE吗?我有将近80个项目并且逐个制作这些项目非常耗时.

谢谢

java eclipse

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

为什么第二次扫描在我的程序中不起作用?

scanf("%d%c",&size,&chara); 有效但单独的scanf用于字符输入不起作用.我在代码中显示了这些内容.这是为什么?

void squareCustomFill(int size, char chara);

int main(void) {

int size,i,k;
char chara;

printf("Enter size of square: ");   //This works
scanf("%d %c",&size,&chara);

//printf("Enter fill character: ");      BUT WHY DOES NOT THIS WORK??
//scanf("%c",&chara);

squareCustomFill(size,chara);

return 0;

 }

void squareCustomFill(int size, char chara){

int i,k;

for (k=1;k<=size;k++){

    for(i=1;i<=size;i++)
        printf("%c",chara);
        printf("\n");

 }
}
Run Code Online (Sandbox Code Playgroud)

c scanf

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

如何在WinForms事件中单击鼠标按钮?

当我们单击鼠标并在我们的.NET程序中触发一个MouseClick事件时,计算机如何知道我们点击了按钮边界中的右边点?

我的意思是幕后发生了什么,为什么我们不需要实现呢?

c# events winforms

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

代表是不变的,但如何?

将方法添加到现有委托时会发生什么?我的意思是当我将method1添加到del时,del保存了method1的地址.当我之后添加method2时,del仍指向Method1,方法2地址插入其底部.这是不是意味着我改变了代表?如果我可以改变这一点,为什么在书中告诉"代表是不可改变的"?

MyDel del = method1; 
del += method2; 
del += method3;
Run Code Online (Sandbox Code Playgroud)

c# delegates

6
推荐指数
2
解决办法
274
查看次数

等待任务完成

我有2个简单的方法,我希望进程在完成之前不会继续.因此,我使用await Task.WaitAll(tasks); 但编译器在这一行给我错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from ' 
'System.Collections.Generic.List<System.Threading.Tasks.Task>' to 
'System.Threading.Tasks.Task'   
Run Code Online (Sandbox Code Playgroud)

我为什么要自己手动转换?我以为这会由编译器来完成......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

internal class Program
{
    public static void Count1()
    {
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine("Count 1 " + i);
            Thread.Sleep(100);
        }
    }

    public static void Count2()
    {
        for (int i = 0; i < 20; i++)
        {
            Console.WriteLine("Count 2 " …
Run Code Online (Sandbox Code Playgroud)

c# async-await

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

为什么控制台上没有打印?

我创建了两个打印x和y 100次的方法.我希望他们运行并发,我希望输出是xxxxyxyxyyyxyyxyx ...这样的sthg.它不打印任何东西.我在这里错过了一些逻辑吗?

using System;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    internal class Program
    {
        public static async Task<int> Print1()
        {
            await Task.Run(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    Console.Write("x");
                }
            });

            return 1;
        }

        public static async Task<int> Print2()
        {
            await Task.Run(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    Console.Write("y");
                }
            });

            return 1;
        }

        public static void Run()
        {
            Task<int> i = Print1();
            Task<int> k = Print2();
        } …
Run Code Online (Sandbox Code Playgroud)

c# async-await

5
推荐指数
3
解决办法
284
查看次数

Task.Delay是如何工作的?

他们说Task.Delay()是一个异步的Thread.Sleep().为了测试这个我写下面的代码.我希望立即打印"One",然后3秒后打印结果变量(15).在此之后2秒,将打印"Two".但它似乎并非如此."One"不会立即打印出来.3秒后打印"One".为什么要等3秒才能打印"One"?

using System;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication31
{
class Program
{
    public static int Multiply(int a, int b)
    {
        return a * b;
    }

    public static async Task DoRunAsync(int m, int n)
    {
        int result = await Task.Run(() => Multiply(m, n));
        await Task.Delay(3000);
        Console.WriteLine("One");
        Console.WriteLine(result);
    }

    static void Main(string[] args)
    {
        Task t = DoRunAsync(3, 5);
        Thread.Sleep(5000);
        Console.WriteLine("Two");
    }
}
}
Run Code Online (Sandbox Code Playgroud)

c# asynchronous

4
推荐指数
3
解决办法
4655
查看次数

在rollDice函数内调用srand(time(NULL))时出现问题

当我在第一次使用 srand(time(NULL))rollDice()功能,它没有工作.但是当我把它放在主要部分时,它可以工作.这是为什么?你能告诉我逻辑吗?

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int rollDice(void) {
    return (1+rand()%6) + (1+rand()%6);
}
int main(void) {
    int roll;
    srand(time(NULL));          
    roll = rollDice();
    printf("You rolled %d.\n", roll);

    enum Gamestatus {WON,LOST,CONTINUE};
    enum Gamestatus status;

    while(status==CONTINUE){
        printf("You are rolling again: \n");
        printf("You rolled %d\n", roll = rollDice());

        if (targetPoint==roll){
            printf("You win!");
            status=WON;
        }
        else if(7==roll){
            printf("You lost!");
            status=LOST;
        }
        else
            status=CONTINUE;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c random srand

3
推荐指数
2
解决办法
9417
查看次数

取消请求返回true时如何做sthg?

下面的代码开始计数,3秒后,它将打印"i"变量的值.程序打印变量,但不会以我想要的样式打印.它不会在if(token.IsCancellationRequested)部分下打印Console.Writeline语句.我认为当取消请求为真时,程序会直接退出.当取消请求为真时,我是否可以打印出console.writeline语句?

using System;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
class Program
{
    private static void Stop(CancellationTokenSource src)
    {
        Thread.Sleep(3000);
        src.Cancel();
    }

    static void Count(CancellationToken token)
    {
        for (int i = 0; i < 100000; i++)
        {
            Console.WriteLine(i);
            Thread.Sleep(80);

            if (token.IsCancellationRequested)
            {
                Console.WriteLine("Current number is :" + i.ToString());
                break;
            }
            else
            {
                Console.Clear();
            }

        }
    }
    static void Main(string[] args)
    {
        CancellationTokenSource src1 = new CancellationTokenSource();
        CancellationToken tkn1 = new CancellationToken();

        var task1 = Task.Run(() => Count(tkn1), tkn1);
        var task2 …
Run Code Online (Sandbox Code Playgroud)

c#

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

标签 统计

c# ×6

c ×3

async-await ×2

asynchronous ×1

delegates ×1

eclipse ×1

events ×1

java ×1

random ×1

scanf ×1

sizeof ×1

srand ×1

winforms ×1