Some Basic in-built Functions


C language contains a number of in-built functions that are used while creating different programms. All the in-built functions has their definitions(prototypes) defined under their respective header files.

Some commonly used in-built Functions

Following are some of the important functions that are used in different programs:

printf() :

This function is defined in <stdio.h> header file. It is used to print message and result on the screen.

Syntax:

1. printf("Welcome To C");

output : Welcome To C (printing only welcome message)

2. int x = 10;

printf("X is : %d",x);

printing the message and value of x on the screen.

output : X is : 10

scanf() :

This function is defined in <stdio.h> header file. This function reads input for numbers and other data types from standard input.

Syntax:

scanf("%d",&variable name)

when we use this function we have to first declare what type of variable it is:-

%d---- for int

%f-----for float

%e-----for double

%c-----for chars

%s-----for strings

Then in the second part we have to use the '&' operator like in a pointer to point the variable instead of just getting its value.

Example:

#include
<stdio.h>
#include <conio.h>

void main()
{

int x;

clrscr(); // Note the functions must be called after declaring the variables in C

printf("Enter number");

scanf("%d",&x);

printf("%d",x);

getch();
}

clrscr() :

This function is defined in <conio.h> header file. It clears text window mode.

Syntax:

clrscr();

getch() :

This is defined in <conio.h> header file. It gets a character from console but not echo to the screen.

getche() :

This is defined in <conio.h> header file. It gets a character from console and echo to the screen.

delay() :

It is defined in <dos.h> header file. It suspends execution for interval in milliseconds.

Syntax:

delay(unsigned milliseconds);

gotoxy():

It is defined in <conio.h> header file. It positions cursor in text window.

Syntax:

gotoxy(int x,int y);

gets() :

It is defined in <stdio.h> header file. It is use to collect a string from stdin.

There are many other inbuilt functions in c language. We will discuss more others in next topics like string manipulation functions, graphics functions, sound function and many other.



     Prev                                                   NEXT

0 comments:

Post a Comment