General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals
  2. Functions

Parameters and arguments

Understanding Parameters and Arguments in Programming

Functions/methods are used to carry out specific tasks. These functions/methods often need to process data, and this is where parameters and arguments come into play. Although they are closely related, they have distinct roles in the context of a function.

Parameters

Parameters are variables that are defined by the function/method that tell it what it needs to work with. They are like placeholders for the data that will be passed into the function. These variables are specified in the function’s definition and dictate the datatypes and number of values the function expects to receive.

Example in C#:

public int AddNumbers(int a, int b) // a and b are parameters with integer datatypes
{
    return a + b;
}

Example in Python:

def add_numbers(a, b): # a and b are parameters but no datatypes are declared
    return a + b

Arguments

Arguments, on the other hand, are the actual data or values you pass into the function/method when you call it. They are the real information that fills the placeholders defined by the parameters. In simple terms, if parameters are the function’s shopping list, arguments are the groceries you are getting from the store.

Example in C#:

int result = AddNumbers(5, 3); // 5 and 3 are arguments

Example in Python:

result = add_numbers(5, 3) # 5 and 3 are arguments

Key Differences

  • Parameters are variables defined by a function to indicate what it needs to operate. They are part of the function’s signature.

  • Arguments are the actual values/data passed to the function when it is called.

Understanding the difference between parameters and arguments, and correctly utilizing them, is crucial for writing efficient and bug-free code. Through parameters and arguments, functions/methods can be more reusable, flexible, and easier to maintain.

PreviousFunctionsNextLambda expressions

Last updated 1 year ago

Was this helpful?