BASIC FUNCTIONS USED IN C-PROGRAMMING
=========================================
(TO WATCH IN VIDEO, CLICK HERE .)
C-language is basically procedural programming language which highly depends on its functions and its use. Inspite of being case sensitive, C provides us the use of its pre-defined functions according to user choices.
These functions are pre-defined under their respective header files.
Before those functions, you should know about the scan formats that are used to input/output to/through a specific datatype.
SCAN FORMAT USED FOR
%d Integer type (signed)
%u Integer type(unsigned)
%ld Long Integer type
%c Char type(character by character)
%s Char type(whole string at a time)
%f Float type
%lf Double type
%Lf Long Double type
SOME OF THE BASIC FUNCTIONS ARE
==============================
1.) printf()
HEADER FILE : <stdio.h>
WORK : Prints messages that it contains.
GENERAL SYNTAX:-
printf("<MESSAGE OR OUTPUT SCAN FORMATS>");
EXAMPLE1:-
printf("MESSAGE");//outputs messages that are in-between the double inverted commas(" ")
OUTPUT: MESSAGE
EXAMPLE2:-
int a=10;//variable a of int type initialised to 10
printf("a= %d",a);
OUTPUT:- a= 10
EXAMPLE3:-
int a=10;
printf("a= %d",a);
OUTPUT:- 10
EXAMPLE4:-
char c[3]="RAM";
printf(c);// here c is providing the base address of the variable
OUTPUT:- RAM
2.) scanf()
HEADER FILE : <stdio.h>
WORK : Inputs data to the variable assigned.
GENERAL SYNTAX:-
scanf("<scan format> ",&variable_name);//inputs data to variable
EXAMPLE1:-
scanf("%d",&a);
EXAMPLE2:-
char b[5];//b variable of char type that can store data upto 5 characters
scanf("%c",&b);
We can assign multiple scan formats too.
EXAMPLE3:-
int a;
char b[10];
float c;
scanf("%d %c %f",&a,&b,&c);
3.) clrscr()
HEADER FILE : <conio.h>
WORK : Clears the contents that are on the OUTPUT screen.
GENERAL SYNTAX:-
clrscr();
EXAMPLE:-
clrscr();
4.) getch()
HEADER FILE : <conio.h>
WORK : Inputs the first keystroke from keyboard.
GENERAL SYNTAX:-
getch();//returns ASCII value of the keystroke to the integer type variable
EXAMPLE:-
int a=getch();
printf("a= %d",a);
OUTPUT:- 49 (keystroke from keyboard is 1)
5.) gotoxy()
HEADER FILE : <conio.h>
WORK : Positions cursor as specified.
GENERAL SYNTAX:-
gotoxy(int x-axis, int y-axis);//positions the cursor coordinates asked accordingly
EXAMPLE:-
printf("ITK");
gotoxy(20,10);
printf("ITKNOWLEDGE");
OUTPUT:-
Many more functions are there that you will face later on this site.
Regards,
ITK
Comments
Post a Comment