0% found this document useful (0 votes)
5 views

Lecture-5 - 6 (Pic) .PDF 7

Uploaded by

sudeshmehar3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture-5 - 6 (Pic) .PDF 7

Uploaded by

sudeshmehar3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAMMING IN ‘C’

 Identifiers are used as the general terminology for the names of


variables, functions and arrays. These are user defined names
consisting of arbitrarily long sequence of letters and digits with
either a letter or the underscore(_) as a first character.
 There are certain rules that should be followed while naming c
identifiers: They must begin with a letter or underscore (_).
 They must consist of only letters, digits, or underscore. No other
special character is allowed. It should not be a keyword.
 It must not contain whitespace.
 It should be up to 31 characters long as only first 31 characters are
significant. Some examples of c identifiers:
Name Remark

_A9 Valid

Temp.var Invalid as it contains special character other than the underscore

void Invalid as it is a keyword


 A C constant refers to the data items that do not change their value during
the program execution. Several types of C constants that are allowed in C
are:
 Integer Constants
Integer constants are whole numbers without any fractional part. It must
have at least one digit and may contain either + or – sign. A number with
no sign is assumed to be positive.
There are three types of integer constants:
 Decimal Integer Constants
Integer constants consisting of a set of digits, 0 through 9, preceded by an
optional – or + sign. Example of valid decimal integer constants
341, -341, 0,8972
 Octal Integer Constants
Integer constants consisting of sequence of digits from the set 0 through 7
starting with 0 is said to be octal integer constants.
Example of valid octal integer constants 010, 0424, 0,0540
 Hexadecimal Integer Constants
Hexadecimal integer constants are integer constants having sequence of
digits preceded by 0x or 0X. They may also include alphabets from A to F
representing numbers 10 to 15.
Example of valid hexadecimal integer constants 0xD, 0X8D, 0X, 0xDD
It should be noted that, octal and hexadecimal integer constants are rarely
used in programming.
 Real(FLOAT) Constants
The numbers having fractional parts are called real or floating point
constants. These may be represented in one of the two forms called
fractional form or the exponent form and may also have either + or – sign
preceding it.
Example of valid real constants in fractional form or decimal notation 0.05,
-0.905, 562.05, 0.015
 Representing a real constant in exponent form
The general format in which a real number may be represented in
exponential or scientific form is
mantissa e exponent
The mantissa must be either an integer or a real number expressed in
decimal notation.
The letter e separating the mantissa and the exponent can also be
written in uppercase i.e. E And, the exponent must be an integer.
Examples of valid real constants in exponent form are:
252E85, 0.15E-10,-3e+8
 Character Constants
A character constant contains one single character enclosed within
single quotes. Examples of valid character constants
‗a‘ , ‗Z‘,‗5‘
It should be noted that character constants have numerical values
known as ASCII values, for example, the value of ‗A‘ is 65 which
is its ASCII value.
 Escape Characters/ Escape Sequences
C allows us to have certain non graphic characters in character constants. Non
graphic characters are those characters that cannot be typed directly from
keyboard, for example, tabs, carriage return, etc.
These non graphic characters can be represented by using escape sequences
represented by a backslash() followed by one or more characters.
NOTE: An escape sequence consumes only one byte of space as it represents a
single character.
 STRING CONSTANTS
String constants are sequence of characters enclosed within double quotes. For
example,
―hello‖
―abc‖
―hello911‖
Every sting constant is automatically terminated with a special
character„‟called the null character which represents the end of the string.
For example, ―hello‖ will represent ―hello‖ in the memory.
Thus, the size of the string is the total number of characters plus one for the
null character.
Escape Sequence Description
a Audible alert(bell)
b Backspace
f Form feed
n New line
r Carriage return
t Horizontal tab
v Vertical tab
\ Backslash
-- Double quotation mark
- Single quotation mark
? Question mark
Null
 SPECIAL SYMBOLS
The following special symbols are used in C having some special
meaning and thus, cannot be used for some other purpose.
[] () {} , ; : * … = #
Braces{}: These opening and ending curly braces marks the start
and end of a block of code containing more than one executable
statement.
Parentheses(): These special symbols are used to indicate
function calls and function parameters.
Brackets[]: Opening and closing brackets are used as array
element reference. These indicate single and multidimensional
subscripts.
 A variable is nothing but a name given to a storage area that
our programs can manipulate.
 Each variable in C has a specific type, which determines the
size and layout of the variable's memory; the range of values
that can be stored within that memory; and the set of
operations that can be applied to the variable.
 The name of a variable can be composed of letters, digits, and
the underscore character.
 It must begin with either a letter or an underscore. Upper and
lowercase letters are distinct because C is case-sensitive.
 Variable Definition in C
A variable definition tells the compiler where and how much storage to create for the
variable. A variable definition specifies a data type and contains a list of one or
more variables of that type as follows−
type variable_list;
 Here, type must be a valid C data type including char, w_char, int, float, double,
bool, or any user-defined object; and variable_list may consist of one or more
identifier names separated by commas. Some valid declarations are shown here −
int i, j, k; char c, ch; float f, salary; double d;
 Variables can be initialized (assigned an initial value) in their declaration. The
initializer consists of an equal sign followed by a constant expression as follows−
type variable_name = value;

 Some examples are −


 extern int d = 3, f=5; // declaration of d and f.
 int d = 3, f=5; // definition and initializing d and f.
 byte z=22; // definition and initializesz.
 char x= 'x'; // the variable x has the value'x'.
 C language offers many types of operators. They are:-
1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical operators
5. Bit wise operators
6. Conditional operators (ternary operators)
7. Increment/decrement operators
8. Special operators
 C Arithmetic operators are used to perform mathematical
calculations like addition, subtraction, multiplication, division and
modulus in C programs.

S.no Arithmetic Operation Example


Operators
1 + Addition A+B

2 – Subtraction A-B

3 * multiplication A*B

4 / Division A/B

5 % Modulus A%B

You might also like