You are on page 1of 30

Dennis Ritchiebetween 1969 and

1973.

APPLICATION OF C PROGRAMMING
ARE LISTED BELOW

C language is used for creatingcomputer


applications
Used in writingEmbedded software's.
For Creating Compiles.
DifferentOperating System Operations.
UNIX kernel

auto, double, int, struct, break, else, long


switch, case, enum, register, typedef, char,
extern, return, union, const, float, short,
unsigned, continue, for, signed, void, default,
goto, sizeof, volatile, do, if, static, while

DATA TYPES

char
int
float
double

Internal representation of values.


Binary Values??
Eg: 5 and -5.

FORMAT SPECIFIERS

%c
char single character
%d (%i) int signed integer
%e (%E) float or double exponential format
%f
float or double signed decimal
%o
int unsigned octal value
%p
pointer address stored in pointer
%s
array of char sequence of characters
%u
int unsigned decimal
%x (%X) int unsigned hex value

Format specifier for binary value??

#include <stdio.h>
int main()
{
int val;
printf(hello %n hello\n", &val);
printf("val = %d\n", val);
return 0;
}
Output:
hello hello
val = 6

#include<stdio.h>
void main()
{
char a= 6;
printf(%d, a);
}
Output:
54
printf("%d",A');
65

FOR WRITING VARIABLE NAME

Variable name can be composed of letters


(both uppercase and lowercase letters),
digits and underscore '_' only.
No Special symbols.
No Keywords.
The first letter of a variable should be either
a letter or an underscore.

#include<stdio.h>
int main()
{
int _=5;
int __=10;
int ___;
___=_+__;
printf("%i",___);
return 0;
}
Ans: 15

#include<stdio.h>
int main()
{
int class=150;
int public=25;
int private=30;
class = class >> private - public;
printf("%d",class);
return 0;
}
Ans: 4

#include<stdio.h>
int main()
{
register x_a=5;
auto b_1=10;
const _1a1_=b_1+~x_a;
printf("%d",_1a1_);
return 0;
}
Ans: 4

in t m ain ()
{
reg ister in t i = 10;
in t *a = & i;
p rin tf("% d ", *a);
g etch ar();
retu rn 0;
}
If you use & operator with a register variable then
compiler may give an error or warning (depending upon the
compiler you are using), because when we say a variable
is a register, it may be stored in a register instead of
memory and accessing address of a register is invalid.

in t m ain ()
{
in t i = 10;
reg ister in t *a = & i;
p rin tf("% d ", *a);
g etch ar();
retu rn 0;
}

registerkeyword can be used with pointer


variables. Obviously, a register can have address
of a memory location.

in t m ain ()
{
in t i = 10;
reg ister static in t *a = & i;
p rin tf("% d ", *a);
g etch ar();
retu rn 0;
}
Register is a storage class, and C doesnt allow multiple
storage class specifiers for a variable. So,registercan not
be used withstatic.

C TOKENS CHART

In C Programmingpunctuation, individual
words, charactersetc are calledtokens.
Tokens arebasic building blocksof C
Programming.

MACROS
#include <stdio.h>
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d\n",foo(i + j, 3));
return 0;
}
Ans: -8

#include <stdio.h>
#define foo(x, y) #x #y
int main()
{
printf("%s\n", foo(a, b));
return 0;
}
Ans: ab

WHAT IS LVALUE ?

Lvalue stands forleft value.

Example of LValue :
#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}
In the above expression, Constant value 5 is being
assigned to a variable num. Variable num is called as
storage regions , num can considered as LValue of an
expression.

IMPORTANT CONCEPTS ABOUT : LVALUE OF AN


EXPRESSION

Tip 1 : Lvalue cannot be a Constant

int main()
{
int num;
5 = num; //Error
return(0);
}

Tip 2 : Lvalue cannot be a Constant Variable


int main()
{
const num;
num = 20; //Error
return(0);
}

Tip 3 : Lvalue cannot be a MACRO


#define MAX 20
int main()
{
MAX = 20; //Error
return(0);
}

Tip 4 : Lvalue cannot be a Enum Constant


enum {JAN,FEB,MARCH};
int main()
{
JAN = 20; //Error
return(0);
}

WHAT IS R-VALUE ?

R Value stands forRight valueof the expression.

Example of RValue :
#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}
In the above example, Constant Value 5 is assigned to the
variable will be considered as right Value of the variable.

IMPORTANT TIPS OF USING RVALUE

Tip 1 : R Value may be Constant or


Constant expression

num = 20; //Constant RValue


num = 20 + 20; //Constant Expression as
RValue

Tip 2 : R Value may be MACRO


#define MAX 20
main()
{
int num = MAX;
}

Tip 3 : R Value may be Variable


#define MAX 20
main()
{
int flag = 0;
int num = flag;
}

Difference between static and Constant???

You might also like