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

多线程循环输出abcc++

Program 1:

程序1:

#include <iostream>
using namespace std;
int A = 5;
int fun()
{
return A--;
}
int main()
{
int A = 5;
while (fun()) {
cout << A + ::A << " ";
}
return 0;
}

Output:

输出:

9 8 7 6 5

Explanation:

说明:

In the above program, we defined a function in which we are accessing the value of the global variable A and decreases it using the post-decrement operator.

在上面的程序中,我们定义了一个函数,在该函数中,我们访问全局变量A的值,并使用减后运算符减小它。

In the main() function, we also declared a local variable A. Both local and global variables contain the same value that is 5.

main()函数中,我们还声明了局部变量A。 局部变量和全局变量都包含相同的值5。

Now look to the while loop, here we used the return value of fun() as a condition in the loop, as we know that condition is true till the returned value is non-zero.

现在来看while循环,在这里我们将fun()的返回值用作循环中的条件,因为我们知道条件是正确的,直到返回的值非零为止。

Note: fun() can't access the local variable A while in the main() global variable A is accessing using the Scope resolution operator (::).

注意:当在main()全局变量A中使用范围解析运算符(::)访问时, fun()无法访问局部变量A。

Interation1: 
The function fun() returns 5, condition is true, and global 'A' become 4. Then
cout<<A+::A<<" ";
Here the above statement will print 5+4 that is 9. 
Interation2: 
The function fun() returns 4, condition is true, and global 'A' become 3. Then
cout<<A+::A<<" ";
Here the above statement will print 5+3 that is 8. 
Interation3: 
The function fun() returns 3, condition is true, and global 'A' become 2. Then
cout<<A+::A<<" ";
Here the above statement will print 5+2 that is 7. 
Interation4: 
The function fun() returns 2, condition is true, and global 'A' become 1. Then
cout<<A+::A<<" ";
Here the above statement will print 5+1 that is 6. 
Interation5: 
The function fun() returns 1, condition is true, and global 'A' become 0. Then
cout<<A+::A<<" ";
Here the above statement will print 5+0 that is 5. 
Interation6: 
The function fun() returns 0, and then condition will be false.
Then the final output will be "9 8 7 6 5".

Program 2:

程式2:

#include <iostream>
using namespace std;
int A = 5;
int& fun()
{
return A--;
}
int main()
{
int A = 5;
while (fun()) {
cout << A + ::A << " ";
}
return 0;
}

Output:

输出:

main.cpp:8:13: error: invalid initialization of non-const 
reference of type ‘int&’ from an rvalue of type ‘int’
return A--;
~^~

Explanation:

说明:

Here, we defined a function that returning the reference.

在这里,我们定义了一个返回引用的函数。

In C++, A function that returns reference will be used as an LVALUE, but in the above program, we are using fun() as an RVALUE.

在C ++中,一个返回引用的函数将用作LVALUE ,但是在上述程序中,我们将fun()用作RVALUE

Read: What do 'lvalue' and 'rvalue' mean in C/C++?

阅读: 在C / C ++中,“左值”和“右值”是什么意思?

Program 3:

程式3:

#include <iostream>
#define MACRO(VAL) (char*)(&VAL + 1) - (char*)(&VAL)
using namespace std;
int main()
{
int i = 1;
int num = 0;
num = MACRO(num);
while (i <= num) {
cout << "India ";
i++;
}
return 0;
}

Output:

输出:

India India India India

Explanation:

说明:

In the above program, we defined a macro MACRO that will calculate the size in bytes of a specified variable just like sizeof() operator, here we calculate the displacement of variable, subtract the current address by next address, then we got different that denotes the size of the variable.

在上面的程序中,我们定义了一个宏MACRO ,它将像sizeof()运算符一样计算指定变量的字节大小,在这里我们计算变量的位移,将当前地址减去下一个地址,然后得到不同的值,表示变量的大小。

Here we used a 32-bit system, then MACRO will return 4 because here we passed an integer variable to it.

在这里我们使用的是32位系统,因此MACRO将返回4,因为在这里我们将整数变量传递给它。

num = MACRO(num);

Then the value of num will be 4. Then the loop will execute 4 times and print "India " 4 times.

然后num的值为4。然后循环将执行4次并打印“ India” 4次。

Recommended posts

推荐的帖子

  • C++ Looping | Find output programs | Set 1

    C ++循环| 查找输出程序| 套装1

  • C++ Looping | Find output programs | Set 2

    C ++循环| 查找输出程序| 套装2

  • C++ Looping | Find output programs | Set 3

    C ++循环| 查找输出程序| 套装3

  • C++ Looping | Find output programs | Set 5

    C ++循环| 查找输出程序| 套装5

  • C++ Operators | Find output programs | Set 1

    C ++运算符| 查找输出程序| 套装1

  • C++ Operators | Find output programs | Set 2

    C ++运算符| 查找输出程序| 套装2

  • C++ const Keyword | Find output programs | Set 1

    C ++ const关键字| 查找输出程序| 套装1

  • C++ const Keyword | Find output programs | Set 2

    C ++ const关键字| 查找输出程序| 套装2

  • C++ Reference Variable| Find output programs | Set 1

    C ++参考变量| 查找输出程序| 套装1

  • C++ Reference Variable| Find output programs | Set 2

    C ++参考变量| 查找输出程序| 套装2

  • C++ Conditional Statements | Find output programs | Set 1

    C ++条件语句| 查找输出程序| 套装1

  • C++ Conditional Statements | Find output programs | Set 2

    C ++条件语句| 查找输出程序| 套装2

  • C++ Switch Statement | Find output programs | Set 1

    C ++转换语句| 查找输出程序| 套装1

  • C++ Switch Statement | Find output programs | Set 2

    C ++转换语句| 查找输出程序| 套装2

  • C++ goto Statement | Find output programs | Set 1

    C ++ goto语句| 查找输出程序| 套装1

  • C++ goto Statement | Find output programs | Set 2

    C ++ goto语句| 查找输出程序| 套装2

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

多线程循环输出abcc++

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/378717.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Opencv——图像金字塔与图像尺寸缩放

主要讲解 1、resize()函数调用 函数定义&#xff1a; 调用方式&#xff1a; resize(srcImage, dstImage, Size(64, 128)); //对图片进行修改 resize(srcImage, dstImage, Size(), 0.5, 0.5);第6个参数的含义&#xff1a; INTER_NEAREST:最邻近插值 (放大好用) INTER_ARE…

java nature_Java中BufferedReader和scanner的对比 - nature

原地址&#xff1a;http://blog.sina.com.cn/s/blog_5fd837410100rtwk.html Scanner 和BufferedReader同样能实现将键盘输入的数据送入程序&#xff0c; import java.io.*; import java.util.Scanner; public class C { public static void main(String []args) throws IOExcep…

13-Canny边缘检测

Canny边缘检测主要思路步骤如下&#xff1a; 1&#xff0c;使用高斯滤波器&#xff0c;以平滑图像&#xff0c;滤除噪声 2&#xff0c;计算图像中每个像素点的梯度强度和方向 3&#xff0c;应用非极大值抑制&#xff0c;以消除边缘检测带来的杂散响应 4&#xff0c;应用双阈值检…

c# uri.host_C#| Uri.IsHexEncoding()方法与示例

c# uri.hostUri.IsHexEncoding()方法 (Uri.IsHexEncoding() Method) Uri.IsHexEncoding() method is a static method or Uri class. Which is used to return that given string is hex-encoded or not? If the given string is hex coded then it returns true otherwise it…

一位老鸟对 23 种设计模式的有趣见解(转)

在网络上流畅很广的一篇旧文&#xff0c;暂时没找到原作者&#xff0c;目前所看到的最早转载时间是 2005 年 2 月 28 日。作者用轻松的语言&#xff0c;形象解释了 23 种模式&#xff0c;有很好的启发作用。创建型模式 1、FACTORY—追MM少不了请吃饭了&#xff0c;麦当劳的鸡翅…

微机原理——移位指令

例题 思路 选择移位语句&#xff0c;右移&#xff0c;将AL移出的送入DX左端&#xff0c;将BL移出的送入DX左端。循环八次 MOV AL,01100101B; MOV BL,11011010B; XOR DX,DX;两个值相同&#xff0c;异或结果为0。等效&#xff1a;MOV DX,0 MOV CX,8;count L1: SHR AL,1;逻辑右…

14-图像金字塔

由第一个图可知&#xff0c;图像金字塔这无非就是对图像进行放大和缩小罢了 1&#xff0c;高斯金字塔 向下采样方法(缩小)&#xff0c;越采样越小&#xff0c;即从金字塔底部向上采样 cv2.pyrDown(img) 向上采样方法(放大)&#xff0c;越采样越大&#xff0c;即从金字塔顶…

JAVA和javascrito_JAVA 和JavaScript的split方法异同

Split的方法很常用&#xff0c;除了str.split("regex")&#xff0c;其实还可以多传一个参数&#xff1a;str.split("regex", limit)。但是要注意&#xff0c;JavaScript和java的split中limit参数作用是不同的。简单说&#xff0c;JavaScript中&#xff0c;…

如果__name__ =='__main__':在Python中怎么办?

In order to understand the details of __name__ variable and the if condition, let us go through a simple exercise. Run a simple python file with just the following lines and run the file as python3 code, 为了了解__name__变量和if条件的详细信息&#xff0c;让…

Eclipse C/C++开发环境搭建

1 Eclipse的安装 到http://java.sun.com/j2se/1.5.0/download.jsp 下载JRE安装&#xff1b; 到http://eclipse.org下载Eclipse安装。&#xff08;这儿可以下载Java版本的&#xff0c;也可以下载C/C 版本的&#xff09; 2 对于下载的Java版本或着只下载Eclipse IDE的&#xff0c…

微机原理——寻址方式总结

一、操作数的寻址方式 立即寻址方式 格式: 操作码 数字表达式&#xff08;将数据送入寄存器中&#xff09; 源操作数可以是8位也可以是16位。 MOV AH, F5H &#xff08;字节操作&#xff09; F5H称为立即数(8位操作数) MOV AL, 8AH &#xff08;字节操作&#xff09; 8AH称为…

15-轮廓检测

边缘是零零散散的&#xff0c;而轮廓是一个整体 cv2.findContours(img,mode,method) img&#xff1a;输入图像对象名称 mode&#xff1a;轮廓检索模式 RETR_EXTERNAL&#xff1a;只检索最外面的轮廓 RETR_LIST&#xff1a;检索所有的轮廓&#xff0c;并将其保存到一条链表当中…

抛硬币仿真实验java_探索HyperLogLog算法(含Java实现)

引言HyperLogLog算法经常在数据库中被用来统计某一字段的Distinct Value(下文简称DV)&#xff0c;比如Redis的HyperLogLog结构&#xff0c;出于好奇探索了一下这个算法的原理&#xff0c;无奈中文资料很少&#xff0c;只能直接去阅读论文以及一些英文资料&#xff0c;总结成此文…

kotlin键值对数组_Kotlin程序以升序对数组进行排序

kotlin键值对数组Given an array, we have to sort its elements in ascending order. 给定一个数组&#xff0c;我们必须按升序对其元素进行排序。 Example: 例&#xff1a; Input:arr [10, 20, 5, 2, 30]Output:sorted array (Ascending Order): [2, 5, 10, 20, 30]在Kotl…

微机原理——总线和时序

前提 8088有两个组态&#xff1a; 最大组态和最小组态&#xff0c;通过引脚MN/MX*的电平决定组态。&#xff08;*表示低电平有效&#xff09; 两种组态没有本质区别。 8088的引脚&#xff1a; 引脚可分为下面几种类别&#xff1a; 1、数据和地址引脚 2、读写控制引脚 3、中断…

PHP站内搜索:多关键字查找,加亮显示

1、SQL语句中的模糊查找LIKE条件一般用在指定搜索某字段的时候, 通过"% _" 通配符的作用实现模糊查找功能&#xff0c;通配符可以在前面也可以在后面或前后都有。搜索以PHP100开头&#xff1a; SELECT * FROM teble WHERE title LIKE PHP100% 搜索以PHP100结束&…

16-模板匹配

cv2.matchTemplate(img,template,cv2.TM_SQDIFF) 参数一&#xff1a;原图图像对象名称 参数二&#xff1a;模板图像对象名称 参数三&#xff1a;差别程度的计算方法(六选一推荐使用带归一化的) 模板匹配和卷积原理很像&#xff0c;模板从原图像上从原点开始滑动&#xff0c;计…

对MySQL性能影响关系紧密的五大配置参数

以下的文章主要是对MySQL性能影响关系紧密的五大配置参数的介绍&#xff0c;我前几天在相关网站看见对MySQL性能影响关系紧密的五大配置参数的资料&#xff0c;觉得挺好&#xff0c;就拿出来供大家分享&#xff0c;望你能有所收获。(一)连接 连接通常来自Web服务器&#xff0c;…

JAVA安装作用_jdk安装配置及其作用

2.安装好了就是去配置路径了&#xff0c;我的是win7系统&#xff0c;步骤如下&#xff1a;桌面上的计算机右击-》高级系统设置—》环境变量-》系统变量-》新建一共要新建三个变量JAVA_HOME,PATH和CLASSPATH1>JAVA_HOME:(这么写为了方便以后可能改动jdk的安装路径&#xff0c…

用C#开发Windows应用程序

To develop windows application, we need to using studio and follow some steps: 要开发Windows应用程序 &#xff0c;我们需要使用studio并遵循一些步骤&#xff1a; Step 1) First of all we launch visual studio. 步骤1)首先&#xff0c;我们启动Visual Studio。 Ste…