C LANGUAGE NOTES
BY
G T CHANDRASEKHAR
Email Address: gtcsekhar@yahoo.com
Some words about Computer Programming languages
Naturally a language is the source of communication
between two persons, and also between person to machine like
computer. The languages we can use to communicate with the
computer are known as Computer programming languages.
Generally there are two major types of languages are available are as follows:
High level languages are further divided into two major categories.
The lists of procedural languages are as follows:
C language
C++ (Object Oriented)
Java (Objected Oriented)
Smalltalk (Objected Oriented)
Pascal language
C LanguageHistory
The Integrated Development Environment (IDE):
Turbo c features as integrated Development environment, or IDE,. It is also referred to as the programmers platform.) in IDE you can able to write/save/open your programs or code, compile using short cut keys, and also perform code debugging very easily.
IDE
Common Short cut Keys Description
F2 press to Save current work
F3 press to open an existing file
ALT-F3 press to close current
ALT-F9 press to compile only
ALT-F5 press to view the desired output of the program.
CTRL-F9 press to compile+run
ALT-X or ALT-F-X press to exit from TC IDE
<Preprocessor Directives (some time necessary)>
<Macros Definition (optional)>
<function declaration>
< Global Variable (on your demand)>
main () (Necessary)
{ statements }
< function definition>
{ }
Remember Some common rules for writing C program
Suppose if you want to use a function clrscr() ; in the main function so must be declared on top # include <conio.h> other wise you could have an prototype error.
Some header files are as follows
Stdio.h
Conio.h
Dos.h
String.h
Stdlib.h
And many more header files are available in C
void main(void)
Every C programs consists of one or more functions. No matter how many
functions there are in a C program , main is the one to which control is passed
from the operating system when the program is run ; it is the first function
executed. The word "void" preceding "main" specifies that the function main()
will not return a value. The second "void," in parenthesis , specifies that the
function takes no arguments.
printf()
printf() is built-in function we can display with printf() any message, variable
value on screen/file/printer.
In printf() we can use many escape sequences and format specifies.
Escape sequences are special notations through which we can display our data
Variety of ways:
Some escape sequences and their functions are as follows:
Escape Sequence | Description | Example |
\n | Perform line feed & Carriage return operation | printf("A\nB"); |
\t | Prints a tab sequence on screen | printf ("A\tb"); |
\ | Prints a single quote character on screen | printf ("\a\"); |
\" | Prints a double quote character on Screen | printf ("\"a\""); |
\r | Perform carriage return operation | printf ("a\rb") |
\b | Remove one character from left | printf ("a\bHi!" ); |
Example Program #1
#include <conio.h>
void main(void)
{
printf( " Example Program (Escape Sequence) \n");
printf( " -----------------------------------------------\n");
printf( "Escape sequnce \t Meaning\n");
printf( " -------------------------------------------------\n");
printf(" \\\\ \t \\" \n");
printf(" \\\ \t \ \n");
printf(" \\\" \t \" \n");
printf(" \\t \t Tab characters or eigth spaces\n");
printf(" \\b \t Erase one char from right to left\n");
printf(" \\r \t perform only line feed\n");
getch();
}
This program produces following output
Example Program (Escape Sequence)
--------------------------------------------
Escape Sequence Meaning
------------------------------------------
\\ \
\
\" \"
\n line feed & carriage return
\t Tab Characters or eight spaces
\b Erase one char from right to left
\r perform only line feed
Example Program #2
#include <conio.h>
void main(void)
{
clrscr();
printf( " \" I LOVE INDIA \" \n");
getch();
}
This program produces following output
" I LOVE INDIA"
Description : in the above we use a escape sequence \" this will produce " on screen after that a messageINDIA ZindaBad is appear after the message another " ( double quotation) appear on screen because of \"
Variable : variables are named peace of memory in which we can store our data and manipulate our data. Variables are used so that same space in memory can hold different values at different times.
In C language following are the list of data type available through which we can define our variables:
Data Types Range Memory occupy
int -32768 to +32767 without fractional) 2 bytes
unsigned int 0 to 65,535 2 bytes
char -128 to 127 1 byte
char 0 to 256 1 byte
enum -32768 to 32,767 2 bytes
float 3.4 * (10**-38) 4 bytes
double 1.7 * (10**-308) 8 bytes
long double 3.4 * (10**-4932) 10 bytes