What is Variable?
- Variable is the name of memory location which can store a single value
- Variable is an identifier (name) for storing a value
- In C before using variables they must be declared.
C Programming Building blocks:
- Character Set: combination of letters (a-z) numbers (0-9) and symbols used in C Programming are Character Set, it is just like alphabet in our languages.
- Keywords: reserved words which have pre-defined meaning, these words can not be used as identifiers.
- Identifiers: Names of any any thing such as Variable name , function name etc are called Identifiers.
- Constants: Any entity whose value can not be changed after execution are called Constants.
- Variables: Names which store values
- Datatypes: They keywords such as int, float, char are called datatypes they are used to create Variables, they denotes the kind of data a variable can store, size of variable and range of values a variable can store.
- Format Specifies: The characters such as %d, %i, %f, %u are called format specifies they indicates the format of data which is to be displayed through some output function such as printf and the format of data which is to be entered through input function such as scanf()
- Escape Sequences: Escape sequences are characters such as \n, \t, \r, \b, \x, \o which breaks the sequence of any string.
- Expressions: The combination of operators and operands for some computation are called expressions.
- Assignments: The expressions which are used to assign some value to an other variable.
- Functions: Any unit of program which perform some task.
- Operators: Any symbol such as +, - , *, / which perform some operation on values called operands.
How to declare Variables in C:
•
In C Programming before using Variables they
must be declared.
Syntax:
<Data
Type> Identifiers
•
Data Type: Data types represent the type / kind
of Data a variable can store and its size. Examples int , char , float, double
etc
•
Identifier is variable name , such as following
line declares Variable a of type int
Int a;
Data Types:
1
|
They are
arithmetic types and are further classified into: (a) integer types and (b)
floating-point types.
|
2
|
Enumerated types
They are again
arithmetic types and they are used to define variables that can only assign
certain discrete integer values throughout the program.
|
3
|
The type void
The type
specifier void indicates that no value is available.
|
4
|
Derived types
They include (a)
Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e)
Function types.
|
Format Specifies :
•
Format Specifiers determines the type of data
which is to be entered or displayed, they are used in two places, Every data
type in C has a format specifiers. Such as int has %d and %i, float has %f,
char has %c and so on.
•
1) In taking Input
•
2) In displaying Output
Format Specifier
|
Description
|
%d or %i
|
Signed decimal
integer
|
%o or %O
|
Unsigned octal
|
%x or %X
|
Unsigned hexadecimal
integer
|
%f, or %F
|
Floating Point
numbers
|
%e or %E
|
Scientific Notation
|
%g or %G
|
Shortest
representation: %e or %f
|
%c
|
Character
|
%s
|
String
|
%p
|
Pointer Address
|
%%
|
%
|
l,h
|
long or short prefix
for: d, i, u, o, x, X
|
Escape Sequence Characters in C
Escape sequence
|
Description
|
\'
|
single quote
|
\"
|
double quote
|
\?
|
question mark
|
\\
|
backslash
|
\a
|
audible bell
|
\b
|
backspace
|
\f
|
form feed - new page
|
\n
|
line feed - new line
|
\r
|
carriage return
|
\t
|
horizontal tab
|
\v
|
vertical tab
|
\nnn
|
arbitrary octal value
|
\xnn
|
arbitrary hexadecimal value
|
\unnnn
|
|
\Unnnnnnnn
|
Operators in C
• What
are Operators:
• The
Symbols or words which perform operation on one or more than one operands
(Values / Variables )
• Arithmetic
Operators
• Unary
Operators : Those Operators which takes only open operand are called Unary
Operators. There are three Unary Arithmetic Operators in C
• Unary
Minus ( –)
• Increment
Operator (++)
• Decrement
Operators (--)
• Binary
Operators: Those Operators which takes two operands are called Binary
Operators: such as: +, -, *, /,^
• Ternary
Operators / Conditional Operators: They
takes three operands and are shortcut to if else, they will be discussed in
later sessions.
C Programming Variables and Data Types |
0 Comments:
Post a Comment