Professional Documents
Culture Documents
Handouts For C Language
Handouts For C Language
1
Introduction to C Language
A Brief History of C
C is a general-purpose language which has been closely associated with the UNIX operating
system for which it was developed - since the system and most of the programs that run it are
written in C.
Many of the important ideas of C stem from the language BCPL, developed by Martin Richards.
The influence of BCPL on C proceeded indirectly through the language B, which was written by
Ken Thompson in 1970 at Bell Labs, for the first UNIX system on a DEC PDP-
7. BCPL and B are "type less" languages whereas C provides a variety of data types.
In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming
Language by Kernighan & Ritchie caused a revolution in the computing world.
C does not use, nor requires the use of, every character found on a modern computer keyboard.
The only characters required by the C Programming Language are as follows:
1. Letter: A–Z or a -z
2. Digits: 0-9
3. Special characters: ~ . , : ; ' $ "# % & ! _ {} [] () | + - / \ * =
The use of most of this set of characters will be discussed throughout the course.
Data types specify how we enter data into our programs and what type of data we enter. C
language has some predefined set of data types to handle various kinds of data that we can use in
our program. These data types have different storage capacities.
C language supports 2 different type of data types:
Derived data types are nothing but primary datatypes but a little twisted or grouped together
like array, stucture, union and pointer.
Data type determines the type of data a variable will hold. If a variable x is declared as int. it
means x can hold only integer values. Every variable which is used in the program must be
declared as what data-type it is.
Integer type
Integers are used to store whole numbers.
Character type
Character types are used to store characters value.
Void type
void type means no value. This is usually used to specify the type of functions which returns
nothing. We will get acquainted to this data type as we start learning more advanced topics in C
language, like functions, pointers etc.
Operators
C programming has wide range of operators to perform various operations. For better
understanding of operators, these operators can be classified as:
Operators in C programming
1. Arithmetic Operators
2. Increment and Decrement Operators
3. Assignment Operators
4. Relational Operators
5. Logical Operators
Arithmetic Operators
* multiplication
/ division
C programming has two operators increment ++ and decrement -- to change the value of an
operand (constant or variable) by 1.
Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two
operators are unary operators, meaning they only operate on a single operand.
C Assignment Operators
An assignment operator is used for assigning a value to a variable. The most common
assignment operator is =
C Relational Operators
A relational operator checks the relationship between two operands. If the relation is true, it
returns 1; if the relation is false, it returns value 0.
== Equal to 5 == 3 returns 0
C Logical Operators
Note:
C language is case sensitive. For example, printf() and scanf() are different
from Printf() and Scanf(). All characters in printf() and scanf() functions
must be in lower case.
return 0;
• Then, user enters a string and this value is assigned to the variable “str” and then
displayed.
#include <stdio.h>
OUTPUT:
int main()
Enter any character
{
a
char ch; Entered character is a
Enter any string ( upto 100 character )
char str[100]; hi
Entered string is hi
printf("Enter any character \n");
• The format specifier %d is used in
scanf("%c", &ch);
scanf() statement. So that, the value entered
printf("Entered character is %c \n", ch); is received as an integer and %s for string.
• Ampersand is used before variable name
printf("Enter any string ( upto 100 character ) \n"); “ch” in scanf() statement as &ch.
• It is just like in a pointer which is used
scanf("%s", &str); to point to the variable. For more
information about how pointer works, please
printf("Entered string is %s \n", str); click here.