C functions with exercise to solve easily.pptx

ranjan317165 11 views 12 slides Aug 22, 2024
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

Simple ppt with test


Slide Content

An Overview By , RANJAN V Asst . Professor, Dept. of AIML, JNNCE

C Functions “A function is a block of code which only runs when it is called.” A function in C is a set of statements that when called perform some specific task. It is the basic building block of a C program that provides modularity and code reusability. The programming statements of a function are enclosed within { } braces, having certain meanings and performing certain operations.

Predefined Functions main() is a function, which is used to execute code, and printf() is a function; used to output/print text to the screen: int main() { printf( "Hello World!" ); return ; }

Create a Function To create (often referred to as declare ) your own function, specify the name of the function, followed by parentheses () and curly brackets {} : Syntax: void myFunction () { // code to be executed }

Call a Function Declared functions are not executed immediately. They are "saved for later use", and will be executed when they are called. In the following example, myFunction() is used to print a text (the action), when it is called:

Example void myFunction() { printf( "I just got executed!" ); } int main() { myFunction(); // call the function return ; }

Calculate the Sum of Numbers void calculateSum () { int x = 5 ; int y = 10 ; int sum = x + y; printf ( "The sum of x + y is: %d" , sum); } int main() { calculateSum (); // call the function return ;} https://www.programiz.com/online-compiler/8uynCFmMSHVSg

EXAMPLE 1:

EXAMPLE 2: https://www.programiz.com/online-compiler/8apOTqMXaewD8

EXAMPLE 3: https://www.programiz.com/online-compiler/5Sq2tjqj56MSc
Tags