LBC PPT All Unit
LBC PPT All Unit
• Definiteness- Every step of the algorithm should be clear and well defined.
int *p;
int number=50;
p=&number
Functions in C
• In c, we can divide a large program into the basic building blocks
known as function. The function contains the set of
programming statements enclosed by {}. A function can be
called multiple times to provide reusability and modularity to
the C program. In other words, we can say that the collection of
functions creates a program.
• A function is a block of code which only runs when it is called.
Types of Function-
• Predefined function (Built-in Function/Library functions)- The
function which is already defined in system. (e.g.
gets(),puts(),printf() scanf() etc.)
• User-defined functions- The function which is created by the
user as per his requirement.
Syntax of Functions in C
The syntax of function can be divided into 3 aspects:
• Function Declaration- In a function declaration, we must provide the
function name, its return type, and the number and type of its
parameters. A function declaration tells the compiler that there is a
function with the given name defined somewhere else in the program.
Syntax-
return_type Name_of_the_function (parameter_1, parameter_2);
Example-
int sum(int a, int b); // Function declaration with parameter names
int sum(int , int); // Function declaration without parameter names
Function Definition
The function definition consists of actual statements which are
executed when the function is called (i.e. when the program control
comes to the function).
return_type function_name (para1_type para1_name, para2_type
para2_name)
{
// body of the function
}
Function Call
• A function call is a statement that instructs the compiler to
execute the function. We use the function name and
parameters in the function call.
Passing Parameters to Functions
The data passed when the function is
being invoked is known as the Actual
parameters.
We can pass arguments to the C
function in two ways:
• Pass by Value
• Pass by Reference
Syntax-
fclose(FILE *fp);
char ch[10]={'j', 'a', 'v', 'a', 't', 'p', 'o', 'i', 'n', 't', '\0'};
Access Strings-
Modify Strings-
Standard Library String Functions:
String Length