C Basics
C Basics
PROGRAMMING
COMPILER
Interpreter
STAGES OF COMPILATION
PREPROCESSING : expand macros,
removing comment lines, included
header files
DATA TYPES
MODIFIERS
ASCII TABLE
Properties of variable
Variable :
A variable is a named object that resides in the RAM
and is capable of being examined and modified.
Types of variable
(a)Variables which can store only one data at time.
Example: integer variables, char variables, pointer
variables etc.
Lvalue
LValue: Lvalue standsforleft value. In any assignment statement LValue
must be a container i.e. which have ability to hold the data. In c has only
one type only container and which is variable. Hence LValue must be any
variable in c it cannot be a constant, function or any other data type of c.
//10=5; LValue cannot be a integer constant
//max=20; //Lvalue cannot be a micro constant
//b=11; Lvalue cannot be a constant variable
//float=3.3f; Lvalue cannot be a data type
//abc={sachin,5}; Lvalue cannot be a data type
//BLUE =2; Lvalue cannot be a enum constant
Rvalue
RValue: In any assignment statement RValue
must be anything which can return and constant
value or it is itself a constant. RValue can be any c
constants, variables, function which is returning a
value etc.
//RValue
//RValue
//RValue
//RValue
//RValue
can
can
can
can
can
be
be
be
be
be
a
a
a
a
a
constant.
constant variable
variable.
enum constant.
function.
Declaration of variables
in c
Declaration of variables means to acknowledge the
compiler only about variable name and its data
type with its modifiers but compiler doesnt reserve
any memoryforthe variables.
(1)Since declaration variable doesnt get any memory
space so we cannot assign any value to variable.
(2)We cannot use any operator with a variable which
has only declared.
(3)We can declare any variable either globally or
locally.
(4)A same variable can be declared many times.
Definition of variables in
c
A c statement in which a variable gets a memory is known as
definition of variable. All auto, register, static and initialized extern
variable are example of definition of variables.
(1)If any variable has not declared then it declaration occurs at the
time of definition.
(2)We can use any operator after the definition of variable.
(3)Definition of variables can be globally or locally.
(4)A register variable gets CPU instead of memory in definition.
(5)A static or extern variable gets memory at the compile time while
auto and register variables get memory or CPU at the run time.
Few questions
Swap two variables without using
third variable.
Write a c program without using any
semicolon which output is: Hello
world.
Operators
What is Operator?
C consists of 45 operators.
Operators specify the basic operations that are to be
performed with the basic data objects.
expression4 + 5 is equal to 9. Here 4 and 5 are called
operands and + is called operator. C language supports
following type of operators.
Arithmetic Operators
Logical (or Relational) Operators
Bitwise Operators
Assignment Operators
Misc Operators
Arithmetic Operators:
Assume variable A holds 10 and variable B holds 20
Bitwise Operators:
Bitwise operator works on bits and perform bit by bit
operation.
Assume if A = 60; and B = 13; Now in binary format
they will be as follows:
A = 0011 1100
B = 0000 1101
----------------A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Assignment Operators:
Misc Operators