C is a structured programming language
C supports functions that enables easy maintainability of code, by
breaking large file into smaller modules
Comments in C provides easy readability
C is a powerful language.
C programs built from
Variable and type declarations
Basic Structure Of “C”
include Header File
/* comments */
/* Function name */
/* comments */
Every program should have main() function
C statements should be terminated by a semi-colon.
An unessential semi-colon if placed by the programmer is treated as an
All statements should be written in lowercase letters. Generally, uppercase
letters are used only for symbolic constants.
Blank spaces may be inserted between the words
It is not necessary to fix the position of statement in the program;
i.e. a programmer can write the statement anywhere between the two braces
following the declaration part.
eg:- a=b+c; d=b*c; 4 or a=b+c; d=b*c;
Standard input and output files.
The most useful formatted printf() and scanf() are
defined in this file.
This file must be included at the top of the program.
Most useful functions from this header files are
printf(), scanf(), getchar(), gets(), putc() and putchar()
Console input and output.
This file contains input and output functions along
with a few graphic-supporting functions.
The getch(), getche() and clrscr() functions are
defined in this file.
This file contains all mathematical and other useful
The commonly useful functions from this files are
floor(), abs(), ceil(), pow(), sin(), cos() and tan().
Write a program to display message
“Hello! C Programmers”
void main( )
Printf(“Hello! C Programmers”);
Hello! C Programmers
Write a program to know about the use of
comments (how to use comments?)
void main( )
clrscr( ); /* Clear the screen */
Printf(“ This program is used to check comment options”); /* how to use
This program is used to check comment options
The tokens are as follows:
Keywords: Key words are reserved by the compiler.
There are 32 keywords (ANSI Standard).
Variables: These are user defined. Any number of
variables can be defined.
Constants: Constants are assigned to variables.
Operators: Operators are of different types and are
used in expressions.
Special Characters: These characters are used in
different declarations in C.
Strings: A sequence of characters.
Identifiers are user-defined names.
They are generally defined in lowercase letters.
However, the uppercase letters are also permitted.
The underscore (_) symbol can be used as an identifier
Valid identifiers are as follows:
length, area, volume, sUM, Average
Invalid identifiers are as follows:
Length of line, S+um, year’s
Integer Constant : These constants are represented with
whole numbers. They require a minimum of 2 bytes and a
maximum of 4 bytes of memory
Numerical constants are represented with numbers. At
least one digit is needed for representing the number.
The decimal point, fractional part, or symbols are not
permitted. Neither blank spaces nor commas are
Integer constant could be either positive or negative or may
A number without a sign is assumed as positive.
Some valid examples:
10, 20, +30, –15, etc.
Some invalid integer constants:
2.3, .235, $76, 3*^6, etc.
Examples of octal and hexadecimal numbers:
– 027, 037, 072
– 0X9, 0Xab, 0X4
Real constants are often known as floating point constants.
Real constants can be represented in exponential or fractional
Integer constants are unfit to represent many quantities.
Many parameters or quantities are defined not only in integers
but also in 11 real numbers.
For example, length, height, price, distance, etc. are also
measured in real numbers.
The decimal point is permitted.
Neither blank spaces nor commas are permitted.
Real numbers could be either positive or negative.
The number without a sign is assumed as positive
Examples of real numbers are 2.5, 5.521, 3.14, etc
Single Character Constants:
A character constant is a single character.
It can also be represented with single digit or a single
special symbol or white space enclosed within a pair of
single quote marks or character constants are enclosed
within single quotation marks
Example: ‘a’, ‘8’, ‘−’
String Constants: String constants are a sequence of
characters enclosed within double quote marks. The
string may be a combination of all kinds of symbols.
Example: “Hello”, “India”, “444”, “a”.
A variable is a data name used for storing a data value.
Its value may be changed during the program execution.
The variable value keeps on changing during the execution of the
program. In other words, a variable can be assigned different
values at different times during the program execution.
A variable name may be declared based on the meaning of the
Variable names are made up of letters and digits. Some
meaningful variable names are as follows.
Example: height, average, sum, avg12
C data type can be classified as
Basic Data Type: Integer (int), character (char),
floating point (float), double floating point (double).
Derived Data Type: Derived data types are pointers,
functions and arrays.
User-defined Type: Struct, union and typedef are user-
defined data types.
Void Data Type
HIERARCHY OF OPERATIONS
Precedence means priority.
Every operator in C has assigned precedence (priority).
An expression may contain a lot of operators.
The operations on the operands are carried out
according to the priority of the operators.
The operators having higher priority are evaluated first
and then lower priority.
Eg:- the operators *, / and % have assigned highest
priority and of similar precedence.
The operators + and − have the lowest priority as
compared to the above operators.
The operator * is the highest priority. Hence, the
multiplication operation is performed first.
The above expression becomes
In the above expression, + and − have the same priority. In
such a situation, the left most operation is evaluated first.
With this the above expression becomes
At last the subtraction operation is performed and answer of
the expression will be as follows:
The logical AND (&&) operator provides true result
when both expressions are true, otherwise 0.
The logical OR (||) operator provides true result when
one of the expressions is true, otherwise 0.
The logical NOT operator (!) provides 0 if the
condition is true, otherwise 1.