相关疑难解决方法(0)

C ++中带逗号的表达式中的执行顺序

据我了解,该术语j = i++i在语句之前执行

j = i, ++i;.

C++ 标准是否保证j = i++i在循环之前执行

for (auto i = std::next(begin), j = begin; i!= end; j= i, ++i)?

c++

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

C++中的变量初始化:一种独特的方法

最近我遇到了这段代码.我不知道为什么我在所有"编码生活"中都没有看到过这种语法.

int main()
{
    int b;
    int a = (b=5, b + 5);

    std::cout << a << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

a的值为10.这种初始化方式到底叫什么?它是如何工作的?

c++ initialization

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

()运算符的返回值

我的方法中的最后一行应该是

return methodName(xxx,xxx);
Run Code Online (Sandbox Code Playgroud)

但我有它

return (xxx,xxx);
Run Code Online (Sandbox Code Playgroud)

方法返回类型是bool,我只是在调试问题时才注意到拼写错误.我没想到return (xxx,xxx);要编译.它究竟做了什么?

c++

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

为什么这个循环无限次运行?for循环中的逗号分隔条件

程序代码:

int main() 
{ 
    int i; 
    for (i = 0; i < 0, 5; i++) 
        printf("%d ", i); 
    return 0; 
} 
Run Code Online (Sandbox Code Playgroud)

上面的循环被无限次执行。

什么i<0,5意思,如何评价?

c

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

我们可以使用 C 中的 return 语句返回多个值吗?如果不能,为什么下面的代码编译成功?

程序为什么以及如何给出输出?

#include <stdio.h>
int sum(int a ,int b , int c ){
    return a , b ,c;
}
int main() {
    int a=10, b=100 , c=1000 ;
    int x = sum(a , b ,c);
    printf("%d %d %d" ,x);
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:1000 1000 100

c return-type return-value

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

C语言中if(a,b,c,d)的含义是什么?

可能重复:
C++逗号运算符

我曾经看过C语言中的语句.像这样.

if (a, b, c, d) {

    blablabla..
    blablabla..

}
Run Code Online (Sandbox Code Playgroud)

这个if语句的含义是什么?

c if-statement

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

为什么会有无限循环?c ++

do{
    cout << "your number"; cin >> z;


   if (z > 4){
    cout << "invalid answer" << endl;}
   else if (z == 4){
   cout << " no" << endl;}
   else {
   cout  <<"great!"   << endl; }
} while (z != 3, 2, 1);
}
Run Code Online (Sandbox Code Playgroud)

我的意见是:提出"你的号码",直到z为3或2或1?怎么了?'

c++ loops infinite while-loop

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

分数运算符

我需要编写一个程序来计算分数,这是我的头文件:

#ifndef FRACTION_H
#define FRACTION_H
#include <iostream>
#include <string>
using namespace std;

class Fraction {

    private:
        int *numer;
        int *denom;
        int gcd(int, int);
    public:
        void reduce();
        int getNum();
        int getDen();
        Fraction();
        Fraction(int numerator);
        Fraction(int num, int den);
        Fraction(string s);  // take string parameter of the form of "numerator/defnominator
        Fraction(Fraction &other);  // copy constructor
        Fraction & operator=(Fraction & rhs);
        ~Fraction();
        // overloading arithematic operation
        Fraction & operator+ (Fraction & rhs);
        Fraction & operator- (Fraction & rhs);
        Fraction & operator* (Fraction & …
Run Code Online (Sandbox Code Playgroud)

c++ string class operator-keyword

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

只有一个变量正在打印 C++

//libraries
#include <iostream>

//standard namepace
using namespace std;


int Car() {
    int a;
    int b;
    
    cout << "Fuel Tank" << endl;
    cin >> a;
    cout << "MPG" << endl;
    cin >> b;

    return a, b;
}
int main() {
    int a;
    int b;
    
    a,b = Car();
    
    cout << "Print Values " << (a,b);    // <--- Line 25

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

假设您将 10 和 15 作为第一个和第二个输入。为什么 15 是cout第 25 行语句中唯一要打印的变量。

c++ visual-c++

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

start=i,end=j 有什么区别; 和开始= i; 结束=j;

问题是“最大连续系列 1”

您将获得一个由 1 和 0 组成的数组。你得到一个整数 M,它表示允许的翻转次数。

找到翻转时将产生最大连续系列 1 的零位置。

我使用滑动窗口方法来解决答案,但是我注意到如果我start=i;end=j;写错了,但是start=i,end=j;是对的。

它们的执行有什么区别?

vector<int> Solution::maxone(vector<int> &A, int B) {
    int n=A.size();
    int start=0,end=0,count=0,i,j;
    
    for(i=0,j=0;j<n;){
        if(B>=0 && !A[j++])
       
        B--;
        
        if(B<0 && !A[i++])
        
        B++;
        
        if(end-start<j-i)
        start=i,end=j;    // Here I get wrong ans if I write start=i;end=j;
    }
    
    vector<int> v;
    while(start<end)
    v.push_back(start++);
    
    return v;
    
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays sliding-window

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