top of page

Functions in C

  • a01337106
  • 12 feb 2015
  • 2 Min. de lectura

C_programming_working_of_functions.jpg

This one is a program in C using functions:

#include <stdio.h>

void suma(int array[],int size);

int main()

{

int N=10;

int A[N];

suma(A,N);

}

void suma(int array[], int size){

int sum=0;

int i;

for (i=0; i<size-1; i++){

sum=sum+1;

}

printf("N-1 es = %d \n",sum);

}

As you can see a function is created before starting the main.

Void is the type of variable that will be returned

Suma is the name of the function

And inside the parenthesis are the external variables that will be used in the function.

After that the main is opened, inside it you can start variables that will be used inside the function. In this case I started an int N and an array A[]. Then, you can attribute the values of those variables to the variables inside the function. This sounds weird but it is easier than that.

We have this statement: (it calls the function)

suma(A,N)

First, it refers to the function, inside the parenthesis is stating (A,B). This refers to the established variables. In the function suma, we used to have the variables (int array[], int size), this variables are being set outside the function, in the main, but with other names. So, we can say that variable A[] is equal toarray[] and that variable N is equal to size. They only have different names inside and outside the function.

After the main the function is written.

First you open the function:

void suma(int array[], int size){

}

And inside the function you can write the code you want. In this case the function sums one each time a loop is executed. The result is N-1.

NOTE: Don’t forget that the value will be called inside the main. It will be called right after it is called.

 
 
 

Comentários


 THE ARTIFACT MANIFAST: 

 

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company. Talk about your team and what services you provide. Tell your visitors the story of how you came up with the idea for your business and what makes you different from your competitors. Make your company stand out and show your visitors who you are. Tip: Add your own image by double clicking the image and clicking Change Image.

 UPCOMING EVENTS: 

 

10/31/23:  Scandinavian Art Show

 

11/6/23:  Video Art Around The World

 

11/29/23:  Lecture: History of Art

 

12/1/23:  Installations 2023 Indie Film Festival

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2023 by Karla Lugo. Proudly created with Wix.com

bottom of page