0% found this document useful (0 votes)
15 views

Part 3, C Library Functions

Part 3, C Library Functions

Uploaded by

dimejihustle16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Part 3, C Library Functions

Part 3, C Library Functions

Uploaded by

dimejihustle16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

COURSE TITLE: COMPUTER PROGRAMMING I

COURSE CODE: CSC 203


NAME OF LECTURER: IBHARALU, F. I.
DEPARTMENT: COMPUTER SCIENCE

1
C Library Functions

The C library functions are provided by the system and stored in the library.

The C library function is also called an inbuilt function in C programming.

To use Inbuilt Function in C, you must include their respective header files,
which contain prototypes and data definitions of the function.

Example of C Program to Demonstrate the Use of Library Functions:

2
Example:
#include<stdio.h>
#include<ctype.h>
#include<math.h>

void main()
{
int i = -10, e = 2, d = 10; //Variables Defining and Assign values
float rad = 1.43;
double d1 = 3.0, d2 = 4.0;

printf("%d\n", abs(i));
printf("%f\n", sin(rad));
printf("%f\n", cos(rad));
printf("%f\n", exp(e));
printf("%d\n", log(d));
printf("%f\n", pow(d1, d2));
}

3
Program Output:

4
Scope of C Variable
A scope is a region of the program, and the scope of variables refers to the area of the
program where the variables can be accessed after its declaration.
In C, every variable is defined in a scope. You can define scope as the section or
region of a program where a variable has its existence; moreover, that variable cannot
be used or accessed beyond that region.
In C programming, variable declared within a function is different from a variable
declared outside of a function. The variable can be declared in three places. These are:

5
Position Type
Inside a function or a block. local variables
Out of all functions. Global variables
In the function parameters. Formal parameters

So, now let's have a look at each of them individually.

6
Local Variables
Variables that are declared within the function block. It can be used only within the
function and is called local variables.
Local Scope or Block Scope
A local scope or block is a collective program statements put in and declared
within a function or block (a specific region enclosed with curly braces) and
variables lying inside such blocks are termed as local variables.
All these locally scoped statements are written and enclosed within left ({) and
right braces (}) curly braces.
There's a provision for nested blocks also in C which means there can be a block
within another block.
So it can be said that variable(s) that are declared within a block can be accessed
within that specific block and all other inner blocks of that block, but those
variables cannot be accessed outside the block.

7
Example:

#include <stdio.h>

int main ()
{
int x, y, z; //local variable definition

// initialization
x = 20;
y = 30;
z = x + y;

printf ("value of x = %d, y = %d and z = %d\n", x, y, z);

return 0;
}
8
Global Variables

Variables that are declared outside of a function block and can be accessed inside
the function is called global variables.

Any function can access variables defined within the global scope, i.e., its
available to the entire program after being declared.

9
Example:

#include <stdio.h>

int globe; //global variable definition

int main ()
{
int x, y; //local variable definition

//initialization
x = 20;
y = 30;

globe = x + y;

printf ("value of x = %d, y = %d and z = %d\n", x, y, globe);

return 0;
} 10
Global Variable Initialization
When a local variable is defined, compiler will not initialize it to any value. You have to
initialize it by yourself. It is an important programming practice to initialize local variables
before they are used. Whereas in contrast, global variables get initialized automatically by the
compiler when defined. Here's how, based on datatype, global variables are defined.
Data type Initial Default Value
int 0
Char '\0'
Float 0
double 0
pointer NULL

11

You might also like