Parameter là gì?

Parameter là tên biến được khai báo trong phần định nghĩa hàm.

Argument là giá trị biến thực được truyền vào khi gọi hàm.

Phân biệt Argument và parameter?

Trong C++

#include "stdafx.h"
#include <iostream>

int Sum(int a /*đây là Parameter*/, int b /*đây là Parameter*/)
{
    return a + b;
}

int main()
{
    std::cout << "Sum Program:" << "\n" << Sum(5 /*đây là Argument*/ ,10 /*cái này cũng là Argument*/) << "\n";
    system("pause" /*và cái này cũng là Argument*/);
    return 0;
}

C

namespace ConsoleApplicationCS
{
    class Program
    {
        static void Main(string[] args /*đây là Parameter*/)
        {
            System.Console.WriteLine("Sum Program:" /*còn đây là Argument*/);
            System.Console.WriteLine(Sum(5, 10 /*đây cũng là Argument*/));
            System.Console.ReadLine();
        }

        static int Sum (int a, int b /*cả 2 đều là Parameter*/)
        {
            return a + b;
        }
    }
}

Viết câu trả lời

Drop Images

0 Bình luận