多线程循环输出abcc++_C ++循环| 查找输出程序| 套装1

多线程循环输出abcc++

Program 1:

程序1:

#include <iostream>

int main()
{
    int i;

    for (i = NULL; i < 5; i++) {
        std::cout << "Hello ";
    }

    return 0;
}

Output:

输出:

Hello Hello Hello Hello Hello

Explanation:

说明:

The above code will print "Hello " 5 times.

上面的代码将打印“ Hello” 5次。

Let's understand the program step by step.

让我们逐步了解程序。

In the above program, we declared an uninitialized variable i.  And initialize variable i  by NULL in the "for" loop. The value of NULL is 0. So the loop will run five times from 0 to 4, it means the condition will be valid up to 4.

在上面的程序中,我们声明了一个未初始化的变量i 。 并在“ for”循环中通过NULL初始化变量iNULL的值为0。因此循环将在0到4之间运行五次,这意味着条件将一直有效到4。

Now, come to the below statement:

现在,进入以下语句:

std::cout<

In the above program, we did not include namespace std. so we have to use std with a scope resolution operator to access the cout object.

Program 2:

Output:

It may not print anything on the console screen.

Explanation:

The above code may not print anything, because, in the above code, we did not initialize variable i, then it will contain garbage value. So the loop will not execute, the condition will be false for the first time.

It may print something if the garbage value of i  is less than 4.

Program 3:

Output:

On 32-bit system: Hello Hello Hello Hello 
On 64-bit system: Hello Hello Hello Hello Hello Hello Hello Hello 

Explanation:

We compiled my program on a 32-bit system, it printed "Hello " 4 times. .

In the above program, we declared a variable i with initial value 0 and we also declared a void pointer.

As we know that the size of any type of pointer is fixed, it depends on the architecture of the system, we are using a 32-bit system, so that size of the pointer will be 4. Then the loop will execute 4 times.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.


翻译自: https://www.includehelp.com/cpp-tutorial/looping-find-output-programs-set-1.aspx

多线程循环输出abcc++

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值