In this blog, you’ll learn the basics of C language—its history, key characteristics, data types, variables, input/output functions, operators, and more. Whether you’re a diploma student or a beginner in coding, this guide will help you build a strong foundation in C with clear explanations and examples.
Note:- This notes are provided by Study Shades Classes, Latur. (KAZI A. S. M.)
Basics of ‘C’ Programming
Introduction of C language
- In 1960, an international committed was set up to develop a general purpose language.
- This committed developed ALGOL 60 in the year 1960.this language
was very abstract. - Combined programming language (CPL) was developed in 1963.But
CPL was very big and had many features. It was difficult to learn and
use. - BCPL was developed in 1967 by Martin Richards. It was not very
powerful. - Ken Thompson simplified BCPL to make B language in 1970. B
represents the first letter of BCPL. This Language was very small. - Dennis Richie by using B, BCPL & some additional feature
developed C language in 1972. Letter C is taken from the second
letter of BCPL.
Characteristics of C language
C language was developed by Dennis Richie at Bell Laboratories in
1972. It is a general purpose, flexible, powerful and structured
programming language. C is used for many applications. It has many
inbuilt functions. It is simple to use and easy to learn friendly, reliable
and compact language. It is case sensitive language. The variable in
upper case & lower case letters has different meaning. It has many library
functions. The user can add new functions. It is high-level language but it
is called middle level language. It has characteristics of both high-level
language & low-level.
Characteristics
- It is simple to use & easy to learn.
- C is reliable language.
The keywords & library functions in C are like English words. - C program can be executed on different computers.
- C compiler is very fast so execution is very fast.
- C compiler is easily available. It requires small disk space for storage.
It is easy to load. - Errors are display on screen. They can be easily removed.
- Program can be divided into small modules by using functions. Program
is easy to understand. - Can be used for recursive programming.
- Can be used for graphic programming.
- Format free language.
- Pointer can be used.
- More data types and more operators than any other language.
- It has many versions such as Turbo C, ANSI C.
- It has the characteristics of both low level & high level language.
- Bitwise manipulate is possible.
- It can be used for structured programming.
- Coding of C program is compact as compared to other languages.
- It can be used for system programming.
- C language has only 40 keywords. They are to learn & use.
Write a program to display message on screen.
void main()
{
clrscr();
printf (“STUDY SHADES IS THE BEST COACHING INSTITUTE FOR ALL LANGUAGE”);
printf(“RESULT OF LATUR ARE ALWAYS 100%”);
printf(“FOR EXCELLENT COACHING CONTACT:-STUDY SHADES”);
getch();
}
Output:-
STUDY SHADES IS THE BEST COACHING INSTITUTE FOR ALL LANGUAGE
RESULTS OF LATUR ARE ALWAYS 100%
FOR EXCELLENT COACHING CONTACT:-STUDY SHADES
Data types in C language
The type of data which a variable can store is called its data type. C
language supports following data types:-
1. Primary data types
2. Derived data types
3. User defined data types
1) Primary data types
a) Integer data type
It is used to store integer value. It required 2 byte memory space. Integer is
declared by the keyword int. Range is from -32768 to 32767. Some
qualifiers Such as short, long, unsigned are used with integer data type can
be used as follows:
int a, b, c;
short int x, y, z;
long int x, y;
unsigned int length;
b) Float data type
It is used to store floating point constants. It requires 4 byte memory space.
Number of digits after decimal are 6. It is declared by keyword float. Range
is b/w 3.4 e -38 to3.4 e 38.
float p,r,t;
C) double data type
It is used to represent real number in exponential form. It requires 8 byte
memory space. Range is from 1.7 e -308 to 1.7 e 308. It is declared by using
the keyword double. Long is used as qualifier.
double x, y;
d) char data type
It is used to store single character or a group of characters. Characters can be
either signed or unsigned. It takes one byte for storage. Range is -128 to 127.
For e.g.-
char name;
e) void data type
It stores nothing. It takes 0 byte. Keyword void is used
2) Derived data type
These data types are derived from primary data types. These are also called
structured data types or secondary data types. they can be further divided
into arrays, function and pointers.
a) Array
An array is a collection of related data items, which have similar data type &
have a common name. It is used to represent a group of related data items.
The data items can be integer, float or character. All the data items must
have same data type & storage class.
e.g.:-
int city[20];
b) Function
A function is a block of statements, which do some useful work. It may
contain a number of statements.
c) Pointer
A pointer is a variable, which points to a location in memory. It contains the
address of another variable or array element
e.g.
int i=5;
int*j;
j=&i;
*j=*(&i) //Asterisk(*)
=*(1001)
=5
3) User defined data types
These are types which are defined by user. Structure, union & enum are user
defined data types.
a) Structures
Structure is a collection of related data items of different data types. A
structure may contain integer elements, floating point elements & character
elements. These elements are called member of the structure. Structure is
similar to a record. For e.g.:-
struct emp
{
char name[25];
int code;
char dept[20];
float salary;
};
struct emp e1,e2;
Here struct is a keyword.emp is the name of the structure,
name,code,dept. & salary are the elements of the structure.e1 & e2 are
structure variables. Member of structure will occupy memory only if
structure variables are created.
b) Union
Union is a data type. it is similar to structure data type. Like structure, union
can also contain members of different data types. However at a time, union
can hold one member. The difference b/w structure and union is that only
one member of the union can contain a value at a given time. Whereas a
structure provide storage for each member a union provide storage for one
member. The space allotted to a union is dependent on the largest member of
union.
For e.g.:-
union student
{
char name[20];
int roll-no;
};
student s1;
The variable s1 can represent either name or roll-no at a time
4) Enumerated
It is used to define the values of user defined data types. For e.g.:-enum day
{Sunday, Monday, Tuesday, Wednesday, Thursday};
Here enum is keyword; day is the name of type.
The following integer values are assigned
Sunday 0
Monday 1
Tuesday 2
Wednesday 3
Thursday 4
Variables in C language
A variable is a quantity, which can change during program execution. It is
the name of the location in the memory of computer in which constant can
be stored. These locations can store intger,float or character constant.
Variable must be declare before it can be used in a program. Variable
declaration tells the compiler about the name of the variable and type of data
which it can hold. When a variable is declared, compiler creates spaces in
memory & gives that name to the space. General form of variable
declaration is:
Data type list of variable separated by comma.
For e.g. :
int a,b;
float x,y;
Here a and b are the variables which can hold integer data.
X and Y are variable to hold float data. We can also assign value to the variable at the time of declaration for e.g.:-
int a=26;
Here a is the name of variable and 26 is stored in this variable.
Following rules are followed to construct variable name:
1.A variable name is a combination of a 1 to 8 alphabets, digit of
underscores.
2.The first character in the variable name must be alphabet or underscore character.
3.Comma and blank space are not allowed in a variable name.
4.No special symbol other than underscore is allowed in variable name.
Keywords in C language
Keywords are predefined words whose meaning is already explained to the
complier. It cannot be used as variable name. Keywords are always written
in lowercase. They are called reserved words. C language has 40
keywords.32 are used for high level programming. These are called standard
keywords. Remaining 8 are used for low level programming. These are
called optional keywords.
Input-output function used in c language
Input-output functions are used to transfer data b/w peripheral devices and memory. C language has no provision for receiving data from input device. It cannot send data to the output devices. So input output operations are done by using standard input output library functions. These functions are kept in special library files. When a particular input output function is required in a program, the corresponding library files is include in the program. Standard input output library function are divided into three type:
a) Console input output functions
b) Disk input output functions
c) Port input output functions
a) Console input output functions
These functions receive input from the keyword and display output on monitor. Following console is input output function.
//write a prog. Sum with 2 variable.
main()
{
int a,b,sum,diff;
printf(“enter the value of a & b”);
scanf(“%d%d”,&a,&b);
sum=a+b;
diff=a-b;
print(“sum=%dndiff=%d”,sum,diff);
}
output
enter the value of a & b= 20 10
sum=30
diff=10
b)Unformatted console input-output function
1) getch ()
It is used to read a single character from keyword. It is non buffered function. Data is directly assigned to variable without pressing enter key. It also maintains the output on screen until we press enter key.
Syntax:- C=getch();
For e.g.:-
main()
{
char ch;
printf(“enter any character”);
ch=getch();/*read a character from keyword*/
printf(“type any character”);
ch=getche();
printf(“u have entered=”);
putchar (ch);
getch();/*to maintain output on screen*/
}
2) getche ()
It is used to read a single character from keyword. It is non buffered function. Data is directly assigned to variable without pressing enter key. When you enter character from keyword, it will be seen on screen. It is an echoed function. It also maintains the output on screen until we press enter key.
Syntax:- C =getche();
For e.g.-
main()
{
char ch;
printf(“enter the any character”);
ch=getche();
printf(“type any character”);
ch=getche();
printf(“u have entered=”);
putchar(ch);
getche();
}
3) getchar()
It is used to read a single character from keyword. It is non buffered function. Data is directly assigned to variable without pressing enter key. When you enter character from keyword, it will be seen on screen. It is an echoed function. It also maintains the output on screen until we press enter key.
Syntax:- C =getchar();
For e.g.:-
main()
{
char ch;
printf(“type any character”);
ch=getchar();
printf(“u have entered”);
putchar(ch);
getch();
}
4) putchar () and putch()
putch() and putchar() print a charcter on screen. They can output only one charcter at a time.
Syntax:-putch(ch);
For e.g.-
main()
{
char ch=‟x‟;
putch(ch);
putchar(ch);
}
5) puts () & gets()
The function gets() receive a string from the keyboard. It is a buffered function. It can i/p multiword.Strings also.
Syntax:-gets (ch);
puts() is an op function. It is used to display a string on screen. It automatically appends a new line character to the op.
Syntax:-puts (ch);
For eg.
main()
{
char ch[24];
puts(“enter data”);
gets(ch);
puts(“Banglore”);
puts(ch);
}
b) Disk input-output function
These function are used to do input & output operations on floppy disk or hard disk. These functions are performed on files. There are many standard library functions to performed disk or file input-output. These functions can be divided into two categories: high level file ip function & low level ip function.
c) Port input & output functions
These functions are used to do input output operation on variable ports.
Identifier:-
These are the names of variables, functions & arrays. It consists of letters,
digits & underscores character ( _ ). Identifiers are of two types: keyword &
user defined identifier.
-Rules for identifier:-
- It must be from the character set.
- First character must be a letter.
- Special character can not be used.
- Avoid single character identifiers. Use combination of letters, digits &
underscore character. - Length must not be more than 8 characters. Some compiles allow 32
character identifiers. - Keyword cannot be used in user defined identifier.
e.g:-si, sum, SUM, a5_4.
Operators in programming in C:-
An operator is a symbol that tells the computer to perform certain
mathematical or logical manipulation.
The various operators in c are as follow:-
1. Arithmetic operators
2. Assignment operators
3. increment/ decrement operators
4. Relational operators
5. Logical operators
6. conditional operators
7. Special operators
8. Bitwise operators
1) Arithmetic operators:-
Arithmetic operators are the simplest & basic operators that do arithmetic operations. These operators require two variables & are called binary operation.
2) Assignment Operator
Assignment Operators are used to assign the result of an expression to a variable.
The most commonly used assignment operator is=assignment expression
that make use of these operator are written in the form.
Syntax:- Identifier=expression
3) Increment/Decrement Operators
These operators have two useful operators. These are increment (++) & decrement (–) operators.
e.g;- x=4;
y=++x;
4) Relational Operators
These operators are used for comparing two values & depending on their relation take certain decision.
e.g.:- 15>25 =True
45<15 = False
5) Logical Operators
These operators are referred to as Boolean operators. These Operators act upon Operators that are themselves logical expression. After testing the value of condition it gives result, which is either true or false.
6) Conditional operators
The conditional operators (?) are used to carry out conditional operators. It can be used in placed & if-else statement. Syntax:-expression1? Expression2: expression3Expression1 is evaluated first. If is true i.e. Value is non-zero. Thenexpression2 is evaluated & becomes value of conditional expression.
7) Special operators
operators:-these operators are divided into two categories.
– Sizeof operator: – the size of operator returns the number of bytes required to represent a data type or variable.
Syntax:-
sizeof(datatype)
sizeof(variable)
The data type can be standard or user defined.
examples:-
sizeof(int)
return value 2
sizeof(float)
return value4
-The comma operators;- a set of expressions is separated by commas in c. it links related expressions together. Expression Linked using comma operators are evaluated from left to right & the value of the right most expression is the result.
e.g.:- x=(y=5, y+6);
The expressions are evaluated from left to right.
x=11
The value of the entire comma separated expression is the value of right most expression.
8) Bitwise operator
operator:-A bitwise operator c has a difference of supporting, several operator known as bitwise operator for manipulation of data at bit level.
Visit diplomachakhazana.com for more notes on programming in C.
Conclusion:
C programming is the backbone of many modern languages and systems. Its simplicity, flexibility, and power make it an essential language for every aspiring programmer. By understanding its history, data types, input/output functions, operators, and structure, you can write efficient and reliable code. The concepts shared in this blog aim to build a strong foundation for diploma students and beginners alike. Practice the sample programs, revise the key points, and you’ll find C both easy to learn and rewarding to master. Keep learning, keep coding!