Tuesday 26 March 2019

CP : Functions - 1


Que: Explain  Function and give one example.

Most languages allow you to create functions of some sort. 
Functions are used to break up large programs into named sections. 
You have already been using a function which is the main function. 
Functions are often used when the same piece of code has to run multiple times.

In this case, you can put this piece of code in a function and give that function a name. When the piece of code is required you just have to call the function by its name. (So you only have to type the piece of code once).

If you don’t want to return a result from a function, you can use void return type instead of the int.

Code: 


#include<stdio.h>

void MyPrint()
{
printf("Printing from a function.\n");
}

int main()
{
MyPrint();
return 0;

}

Output: 


No comments:

Post a Comment

LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project

  LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project Dear All We will learn how to Connec...