📜  操作数的评估顺序

📅  最后修改于: 2021-05-25 23:48:11             🧑  作者: Mango

考虑下面的程序。

C++
// C++ implementation
#include 
using namespace std;
int x = 0;
 
int f1()
{
    x = 5;
    return x;
}
 
int f2()
{
    x = 10;
    return x;
}
 
int main()
{
    int p = f1() + f2();
    cout << ("%d ", x);
    getchar();
    return 0;
}


C
#include 
int x = 0;
 
int f1()
{
    x = 5;
    return x;
}
 
int f2()
{
    x = 10;
    return x;
}
 
int main()
{
    int p = f1() + f2();
    printf("%d ", x);
    getchar();
    return 0;
}


Java
class GFG {
 
    static int x = 0;
 
    static int f1()
    {
        x = 5;
        return x;
    }
 
    static int f2()
    {
        x = 10;
        return x;
    }
 
    public static void main(String[] args)
    {
        int p = f1() + f2();
        System.out.printf("%d ", x);
    }
}
 
// This code is contributed by Rajput-Ji


Python3
# Python3 implementation of the above approach
class A():
    x = 0;
 
    def f1():
        A.x = 5;
        return A.x;
 
    def f2():
        A.x = 10;
        return A.x;
         
# Driver Code
p = A.f1() + A.f2();
print(A.x);
 
# This code is contributed by mits


C#
// C# implementation of the above approach
using System;
 
class GFG {
 
    static int x = 0;
 
    static int f1()
    {
        x = 5;
        return x;
    }
 
    static int f2()
    {
        x = 10;
        return x;
    }
 
    // Driver code
    public static void Main(String[] args)
    {
        int p = f1() + f2();
        Console.WriteLine("{0} ", x);
    }
}
 
// This code has been contributed
// by 29AjayKumar


PHP


Javascript


输出:

10
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。