declare functions in c code example

Example 1: declare variable in c

int    i, j, k;
char   c, ch;
float  f, salary;
double d;

Example 2: function in c

#include <stdio.h>

void function(){
  printf("I am a function!");
}

int main(void) {
  
  function();
}

Example 3: how to write function in c

#include <stdio.h>

// Here is a function declaraction
// It is declared as "int", meaning it returns an integer
/*
	Here are the return types you can use:
    	char,
        double,
        float,
        int,
        void(meaning there is no return type)
*/
int MyAge() {
	return 25;
}

// MAIN FUNCTION
int main(void) {
	// CALLING THE FUNCTION WE MADE
    MyAge();
}

Example 4: functions in c programming

#include <stdio.h>
/* function return type is void and it doesn't have parameters*/
void introduction()
{
    printf("Hi\n");
    printf("My name is Chaitanya\n");
    printf("How are you?");
    /* There is no return statement inside this function, since its
     * return type is void
     */
}

int main()
{
     /*calling function*/
     introduction();
     return 0;
}

Example 5: declare structure in c

struct num{
 int a ;
 int b;
};

int main()
{
    struct num n;
    //accessing the elements inside struct
    n.a=10;
    n.b=20;
}