Over view of C language
SHARE WITH OTHER FELLOWS |
• C is developed by Dennis Ritchie in 1972 at AT&T (American
Telephone and Telegraph) Bell Labs USA.
• C is a structured programming language
Files used in C program
Library files
Library files used to perform specific task for example printf() file use to display the text on the screen.
Header files
The sub directory called “include” contain header files
These files are text files, like the one you generate with a Turbo
C editor. Header files can be combined with your program before it is compiled.
Each header file has a ”.h” file extension.
Header files in c language
Uses of functions
Main
This is the entry point of a program
When a file is executed, the start point is
the main function.
Getch()
The function use to get single character from
user
The
getch() function is defined in conio.h header file. The character user entered
can also stored in variable. e.g ch = getch();.
Printf();
This is
a function from the library that prints on the screen and is accessible through
the header file stdio.h.
Scanf();
Scanf();
function is used to take input from the users.
Data
type in C language
A data-type in C programming is a set of values
and is determined to act on those values.
Format
Specifier
Format Specifier tell the printf
statement where to put the text and how to display the text. The various format
specifiers are:
%d =>
integer
%c =>
character
%f =>
float
%e =>
displays number in scientific notation (float)
%s
=>displays a string
%o
=>displays an octal number (unsigned)
%x
=>displays a hexadecimal number (unsigned)
Variables
and Constants
If
the value of an item is to be changed in the program then it is a variable. If
it will not change then that item is a constant. The various variable types
(also called data type) in C are: int, float, char, long ,double etc they are
also of the type signed or unsigned.
Escape
Sequences
Escape sequence tells the printf() the
alignment of statement ,weather it is
new line or new tab. The back slash “\” character is called the “Escape
Character”. The escape sequence includes the
following:
\n => new
line
\t =>
horizontal tab
\b => back
space
\r =>
carriage return
\’ =>single
quote
\” => double
quotations
\\ => back
slash
\v
=>vertical tab
\a =>alert
\?
=>Question mark
\0 =>Null
\f
=>form feed, page eject, page or section separator (move active
position to the initial
position of next logical page)
\xhh =>hexa
decimal escape sequence
\ddd =>octal
escape sequence
Taking
Input from the User
The input from the user can be taken
by the following techniques: scanf( ), getch(), getche( ), getchar( ) etc. getchar() is a standard function that gets a character from the stdin.
e.g: char c;
printf(“Enter character”);
c= getchar();
getch() is a nonstandard function that gets a character from keyboard,
does not echo to screen. getche() is a nonstandard function
that gets a character from the keyboard, echoes to screen.
Use getchar() if you want it to work on all compilers. Use getch() or getche() on a system that supports it when you want keyboard input without
pressing [Enter].
Operators
There are various types of operators
that may be placed in three categories: Basic: + -
* / %
Assignment: = +=
-= *= /= %=
Increment / decrement operators
++,--
Relational: < >
<= >= == !=
Logical: && , || , !