You are on page 1of 3

INTRODUCTION TO C PROGRAM \v Vertical tab \\ backslash

\n New line \0 Null character


Character set: Character-set refers to the set of alphabets, letters and some special characters that are valid in
C language. \f Form feed \’ Single quote

For example, The characters in C are: Letters A-Z, a-z, both upper case and lower case, Digits 0-9, Symbols such as
+ - * / % and white spaces. Data types: The data type defines the type of data stored in a memory location. In C language the data types
are mainly classified as:
Tokens: It is the smallest individual elements or units in a program are called as Tokens. C has following tokens.
1) Primary data type (int, char, float, double, void)
(a) Identifiers (b) Keywords (c) Constants (d) Operators (e)Special characters
2) Derived data type(arrays)

on
Identifiers: Identifiers are the names given to program elements such as variables, constants, function names, 3) User defined data type(structure, enum, union)
array names etc. It consists of sequence of one or more letters or digits along with “_” (underscore). The letters C supports 5 primary data types:
are characters from ‘A’ to ‘Z’ or ‘a’ to ‘z’. The digits are from ‘0’ to ‘9’.
1) int: An int is a keyword which is used to define integers in C language. Using int keyword, the

ti
Rules to frame and identifier are:
programmer can inform the compiler that the data associated with this keyword should be treated as integer.

ec
❖ The first character in the identifier should be a letter or “_”(underscore). There are 3 different sizes of integer data type namely: short int, int, long int.
❖ The first character can be followed by any number of letters or digits or underscore.
2) float: A float is a keyword which is used to define floating point numbers.
❖ No special characters are allowed except “_” (underscore).
❖ Length of an identifier can be a maximum of 31 characters. 3) double: A double is a keyword which is used to define long floating point numbers.

fs
❖ Keywords cannot be used as an identifier.
❖ Identifiers are case sensitive. It means that words such as “sum”, ”Sum” and “SUM” are all different 4) char: char is a keyword which is used to define single character or a sequence of characters (string).
identifiers. 5) void: void is an empty data type. Since no value is associated with this data type, it does not occupy any
Keywords: The tokens which have predefined meaning in C language are called keywords. Since they are space in the memory.

cs
reserved for specific purpose in C language, they are also called as reserved words. Example: int, if, continue,
Data types Bytes Range of data type
case, char, return etc.
char 1 bytes -128 to 127
❖ The keywords should not be used as variables, function name, array names etc.
❖ The meaning of the keywords cannot be changed by the user. int 2 bytes -32,768 to 32,767
❖ All keywords should be written in lower case letters.

K
Constants: A constant is a value which will not change during the execution of a program. The constants cannot
float 4 bytes 3.4E-38 to 3.4E38
B.
double 8 bytes 1.7E-308 to1.7E308
be modified in the program. For example: 10 is an integer constant, 12.5 is a floating point constant.

Different types of constants:


K.
Variable: A variable is a name given to a memory location where the data can be stored. Using the variable
⮚ Integer constant Ex: 10, 07, 99 etc. name, the data can be stored in a memory location and can be accessed or manipulated very easily.
⮚ Floating point constant Ex: 10.5, 12.9 etc.
Input and Output Functions:
⮚ Character constant Ex: ‘a’, ‘9’, ‘\n’ etc.
H.

⮚ String constant Ex: “HKBK”,”9” etc. Printf function: The function ‘printf’ means print the data in the specified memory locations after formatting the
data (i.e. converting the data into proper data type).
Escape sequence in C: An escape sequence character begins with a backslash and followed by one character. A
Syntax: printf(“ format string ”, list of variables);
backslash (\) along with some characters give rise to special print effects by changing (escaping) the meaning of
some characters. Format Specifiers: Format specifier tells the compiler which type of value is to be printed or read. The various
types of format specifiers supported by C language that can be used in printf() are:
Escape sequence Character Escape sequence Character
\b Backspace \r Return Format specifiers Function
%d Used for ‘int’ data type is used. The data displayed will be in decimal form
\t Horizontal tab \? Question mark
%c Used when a ‘char’ data type is used. The data displayed is a character. An opeartor may be associated with one or two or three operands.
%f Used when a ‘float’ data type is used. The data displayed is a float.
Classification based on the number of operands
%lf Used when a ‘double’ data type is used. Data displayed is a long float.
Scanf Function: Scanf is a function that reads formatted data from standard input stream (which is usually a Operators : Unary operators Ex: ++,--etc
keyboard) and then writes the result into the arguments given.
Binary operators Ex: +,-,*,/etc
Syntax: scanf(“ format string “, address list);
Ternary operators Ex: ? and :
The format string contains one or more format specifiers. A format specifier starts with % sign and is followed by
conversion code. The address of each variable should be specified in the address list. The address of the variable Special operators Ex: comma(,), sizeof()etc.
can be obtained by preceding the variable with ‘&’ symbol. Classifcation based on the type of the operation

on
Basic Concepts of C program: The basic concepts of a C program can be shown by writing the structure of C Types of operators:
program. The structure of C programs is the rules that are to be followed while writing a C program. The
structure of the C program is given as: ⮚ Arithmetic operators Ex: +,*,-etc.
⮚ Assignment operators. Ex: =,+=etc.

ti
[Comments] ⮚ Increment /Decrement operators. Ex: ++,--
[pre-processor directives]

ec
⮚ Relational operators Ex:<,<=,etc.,
[global declarations] ⮚ Logical operators. Ex:&&,||etc.
[function declarations]
⮚ Conditional operators. Ex:?:
main()
⮚ Bitwise operators. Ex:&.^,etc.,

fs
{
⮚ Special operators. Ex: , . [] etc.,
[Declaration section] [Executable
section] } Arithmetic Operators: The operators that are used to perform arithmetic operations such as addition,
subtraction, multiplication,division and modulus operations are called arithmetic operators.
Comments: Comment consists of short descriptions explaining the purpose of each statement or a set of
statements in a program. It makes the program easy to understand and helps us modify the program easily. Any Description Symbols Meaning Example result

cs
comment must start with /* and end with */ and the comments can appear anywhere in the program.
+ Add 4+2 6
Preprocessor directives:The pre-processor statements start with a ‘#’ symbol. These statements instruct the Addition
compiler to include some of the files in the beginning of the program. For example #include<stdio.h> Subtraction - Subtract 4-2 2

be accessed by all the functions.

K
Global declaration: The variables that are declared before all the functions are called global variables. They can
Multiplication
* Multipliy 4*2 8
B.
Program header: In C programme, the execution always starts from the function main and it can be written as Division / Gives quotient 4/2 2
void main()
Modulus % Gives reminder 4%2 0
Body of the program: A series of statements that perform a specific action will be enclosed within braces ‘{‘ and
K.
‘}’ and present immediately after the program header is called body of the program. This contains:

1) Declaration section: The variables which are used inside the function should be declared in the Type conversion : (a) Implicit conversion (b) Explicit conversion
declaration section. The variables can also be initialised. Data type with higher rank
H.

2) Executable section: These are building blocks of any program. They represent the instructions given to
the computer to perform a specific task. An instruction may represent an expression to be evaluated,
input/output statement, etc. Each executable statement ends with a “;”.

Operators And Expressions

Operator : An operator is a symbol (or a token) that specifies the operation to be performed on
Arithmetic operator’s precedence (Precedence of operators)
Various types of operands. For example: The symbol like +,-,*,% and /.
Description Priority Associativity
Operand: A constant or a variable or a function which returns a value is an operand.
Multiplication Divison Modulous 1 Left to right
Addition Subtraction 2 Left to right }

Relational operators: The operators that are used to find the relationship between two operands are called (c) Control statement: enable us to specify the flow of control. i.e., the order in
which the instruction in a program must be executed
relational operators.

Description Priority Associativity


Less than Lesser or equal Greater Greater or equal 1 left to right
Equal to Not equal to 2 Left to right
Assignment statements

Simple assignment statement: An assignment statement sets or resets the value stored in the storage

on
location denoted by a variable name.i.e.,it copies a value. Ex:C=A+B will assign value of A+B into C.

Compound assignment statement :The compound assignment statement enable us to abbreviate assignment
statements.Ex: The “+=” operator adds right operands to the left operand and assign the result to left operand.

ti
Increment operator (++): Increment operator increases integer value by one. Ex:- ++A will give 11 which is

ec
called pre increment and A++ will give 10 for evaluation then A will be incremented to 11 which is called post
increment.

Decrement operator(--):-Decrement operator decreases integer value by one. Ex:A will give 9 which is called
pre decrement and A—will give 10 for evaluation then A will be decremented to 9 which is called post

fs
decremented.

Conditional operator (?:) : Conditional operator is a ternary operator. The conditional operator works as
follows: If the first operand evaluates to true(1), the second operand is evaluated else If the first operand
evaluates to false(0), the third operand is evaluated. Ex: a=x<y?x:y. If condition is true. Then value of a=x ,

cs
otherwise value of a= y.

Bitwise operator: Bitwise operator work on bits and perform bit-by-bit operation.Ex. +=,-=,*= etc.

Special operators: The special operators are:

(2) * :- Pointer to a variable. Ex: *a; will SPECIAL pointer to a variable.


K
(1) & :- Returns the address of an variable. Ex: &a; will give actual address of the variable.

(3) Size of() :- Returns the size of a variable. Ex: sizeof(a), where a is an integer, will return 4.
B.
Precedence of operators :- If more than one operators involved in an expression then,C language has predefined
rule of priority of operators. This rule of priority of operators is called operator precedence.
K.
H.

Statements: is a programming construct that is used to inform the computer to perform an action when
program is executed. A expression becomes a statement when terminated by semicolon. Ex. Sum=0; where
sum=0 is a expression.

Types of statement: (a) Expression statement: expression followed by a semicolon. Ex. j++;
(b) Compound statement: sequence of statements enclosed in pair of braces.
Ex. {
printf(“Area + %d”, length*breadth);

You might also like