Starting of C
Starting of C
In earlier days, every language was designed for some specific purpose.e.g FORRTRAN
(Formula Translator) was used for scientific and mathematical applications, COBOL
(Common Business Oriented Language) was used for business applications. So need of such
a language was felt which could withstand most of the purposes. From here the first step
towards C was put forward by Dennis Ritchie.
The C language was developed in 1970’s at Bell laboratories by Dennis Ritchie. Initially it
was designed for programming in the operating system called UNIX. After the advent of C,
the whole UNIX operating system was rewritten using it.
The C language is derived from the B language, which was written by Ken Thompson at
AT&T Bell laboratories. The B language was adopted from a language called BCPL(Basic
Combined Programming language), which was developed by Martin Richards at Cambridge
University.
In Short
C LanguageHistory
Characteristics of C
It is portable.
It is simple and reliable.
C is case sensitive.
C is expandable.
C is structured programming language.
It is a high level language.
Note:
C is a high level language but has the capability of middle level language.
In this category we are able to create our project or programs using procedural approach means
in this type we can able to divide our big project/program into small subroutines or procedures.
After making procedures we can able to call a ‘procedure’ one or more places.
C language
Pascal language
2. Non-Procedural Languages: This category also known as ‘Problem Oriented languages’. In this
type of languages we can able to make program only at specific range like database. The
followings are the examples of Non procedural languages
Translators
The three types of translators are:-
Assembler
Compiler
Interpreter
Assembler is used to convert the code of low level language into machine level language.
Compilers are used to convert the code of high level language to machine level language.
Keywords are the words whose meaning has already been explained to the C compiler (or in a broad
sense to the computer). The keywords cannot be used as variable names.
Header Files or Preprocessor Directives contains references or links of library functions. That is built-
in in the C language.
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.
Stdio.h
Conio.h
Dos.h
String.h
Stdlib.h
- Library functions are provided along with the compiler inside special files called as header files
(.h)
o stdio.h – Standard Header File – printf(), scanf() etc.
o math.h – Mathematical functions – pow(), log() etc.
o conio.h – Console Input/Output – clrscr(), gotoxy(), textcolor(), textbackground() etc.
- We need to import the header files into our programs to use their library functions
- Use #include pre-processor directive to add the header files using any of two methods
o #include <filename.h>
o #include “filename.h”
Void main()
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.
C character set
a. Alphabets
A,B,C……………..Y,Z
A,b,c,d,……………..x,y,z
b. Digits
0,1,2,3,4,5,6,7,8,9
c. Special characters
Void main()
Printf(“hello to C”);
}
OR
# include ”stdio.h”
Void main()
Printf(“Hello to C”);
Hello to C
Note:
Put the cursor inside function, keyword or header file and press Ctrl+F1(For help)
printf()
printf() is built-in function we can display with printf() any message, variable
value on screen/file/printer.
Escape sequences are special notations through which we can display our data
Variety of ways:
Example Program #2
#include <stdio.h>
#include <conio.h>
void main()
clrscr();
getch();
}
WHAT IS AN IDENTIFIER?
An identifier is used for any variable, function, data definition, etc. In the C programming
language, an identifier is a combination of alphanumeric characters, the first being a letter of the
alphabet or an underline, and the remaining being any letter of the alphabet, any numeric digit, or
the underline.
Data types in C
- Special keyword defined by C language to specify the kind of data and amount of data
- Data types can be three types
o Primary Data Types
o Modified Data Types
o Derived Data Types
- Primary Data Types
o The data types that uniquely defines a type
int – 2 or 4 bytes
char – 1 byte
float – 4 bytes – 6 dp
double – 8 bytes – 14 dp
void - nothing
- Modified Data Types
o The data types created by modifying the primary types using special keywords called
modifiers
short
long
signed
unsigned
o char
signed char or char
unsigned char - 0 to 255
o int
unsigned int
short int or short– 2 bytes
long int or long – 4 bytes
unsigned short int or unsigned short
unsigned long int or unsigned long
o double
long double – 10 bytes
- Derived Data Types/User Defined Data Types (UDT)
o Made of primary and modified data types
o Arrays, Structures, Unions, Bit fields, Enumerators etc.
Variables
- A name given to some position in memory to store and retrieve the data
- A variable name must have a data type associated with it
Syntax
datatype variable;
Example
char gender;
int empid;
double amount;
Format Specifiers
- Special codes defined to format the data for input and output
- They starts with %
o %d – decimal
o %o – Octal
o %x or X – Hexa decimal
o %i – int
o %f – float
o %ld – long int
o %lf – double and long double
o %c – character
o %s – string without space
o %[^\n] - string with space
o %p – To show address in hexa
o %u - unsigned
- They are used with functions to input and output like printf(), cprintf(), sprintf(), scanf() etc.
o printf(“specifiers”,variable or value);
Example
int num=456;
Assignment
Variable Vs Constants