OneBite.Dev - Coding blog in a bite size

declare a simple function in C

Code snippet on how to declare a simple function in C

  int myFunction(int a, int b) 
  { 
    int c = a + b; 
    return c; 
  } 

This code creates a function called ‘myFunction’ that takes two integers as parameters (a and b) and returns the sum of those integers. The code begins by declaring the function with the keyword ‘int’ to indicate that it will be returning an integer. The function is given two parameters of type ‘int’, and then it creates an integer ‘c’ that is the sum of the two parameters. Finally, the function ‘returns’ the value of ‘c’ which is the sum of the two parameters passed in.

c