You are on page 1of 36

Name of

variable

Memory

NESO ACADEMY
DECLARATION

Declaration:announcingthe properties of
variable tothe compiler

Properties:

1. Size of the variable


2. Name of the variable

NESO ACADEMY
DEFINITION

Definition: allocating memory to a variable

Most of the time declaration and definition will

be done at the samne time.

NESO ACADEMY
int var;

Data type:how much spacea variable is

going to occupy in memory.

Name of variable

NESO ACADEMY
INITIALIZATION

int var = 3;

NESO ACADEMY
Variable :
vary- able

NESO ACADEMY
initialization.c- Code-Blocks 16.01

File Edit View Search Project Build Debug Fortran wSmith Tools Tools Plugins DoxyBlocks Settings Help

Management
Start here xinitialization.c

x
Projects Symbols
#include <stdio. h>
CUsers\jaspr\ Downloads\C programs of dennis ritchie\initialization.exe"
OWorkspace
3 int main () 4
4 Process returned e (exe) execution time : e.5es s
5 int var 3: Press any key to continue.
6 var,, 4:
7 pritf("$d", var):
return 0;

10

Logs & others


4A Code::Blods x9Search results xCccc X

File L...Message

= Build
Build
file:
finished:
"no targe
0 err
initialization.c - Code:-Blocks 16.01

File Edit View Search Project Build Debug Fortran wSmith Tools Tools+ Plugins DoxyBlocks Settings Help

Management
Start here initialization.c x
Projects Symbols
#include <stdio.h>
O Workspace 2
3 int main ()
CUsers\jaspr\ Downloads\C programs of dennis ritchie\initialization.exe"
4
5 int varl 3:
6 int var2: Press returned e (exe) execution time : e.569 s
var2 varl; - Press any key to continue.
8 printf ("&d", var2) :
9 return 0;
10
11

Logs & others


4Code::Bloks x9 Search results x Cccc x Buld log xBuild messagesx CppCheck h CppChedk messages XACscope
File L...Message
Build file: "no target" in "no project" (compiler: unkn...
mBuild finished: 0 error (s) ,
0 warnirg(s) (0 minute (s) , .
initialization.c - Code:Blocks 16.01

File Edit View Search Project Build Debug Fortran wSmith ools Toolst Plugins DoxyBlocks Settings Help

Management
Start here initialization.c x
Projects Symbols
4include <stdio.h>
OWorkspace 2
3 int main () CAUsers\jasp\Downloads\C programs of dennis ritchie

444
int varl, var2, var3: Rpcess returned e
(ex0) execution time :€
varl = var2 = var3 4: = Press any key to continue.
printf ("$d",varl)
printf ("%d",var2) ;
printf ("%d",var3) ;
10 return

0;
11
12

Logs & others


4A Code::Blocks x9Search results xACccc x Build log Build messages x

File L... Message


== Build file: "no target" in "no project" (compiler:
=Build finished: 0 error (s) ,
0 warning (s) (0 minute
C

PROGRAMMING AND
(DATASTRUCTURES
Naming conventions of
variables
Variable name: composed of letters or combination
of letters (both upercase and lowercase) and digits.
Rule #1: don't start variable name with digit.

globe 2globe

X
Rule #2:begining with underscore is valid but not
recommended.

-(underscore) is treated as letter.


Rule #3:C langauge is case sensitive.Uppercase
letters are differentfrom lowercase letters.

var,Var, VaR,VAR, VAr, VAR all are different.


Rule #4: specialcharacters (®, #,%,^,&. *.) not
allowed in the name of variable.
Rule #5: Blanksor white spaces not allowed.
Rule #5: Blanks or white spaces not allowed.

Are they
together ?

int my variable
Compiler
Rule #5: Blanks or white spaces not allowed.

int my_variable
Rule #5:Blanks or white spaces not allowed.

They are
together

int my_variable
Compiler
Rule #6: Don't use keywords to name your variables.

Cannot Use if, else,for, while,switch, int,float, long.


double etc...

Can use IF,ElsE,For, WHiLE Switch, INT,FLOAt,


|LOng,DoUBle etc..
Do notuse loooooonnngggg..namesfor your
variables.
C

PROGRAMMING AND
DATA STRUCTURES
Basic output function -printf.
NESOACADEMY
FILL IN THE BOX

Fill in the valid name for a variable below.

int Switch

369
int
@go while
Switch

NESO ACADEMY
RECALL THESE CODE SNIPPETS

printf("NesoAcademy" ); From Lecture 2

printf( "%d", var); From Lecture 4

printf("%d %d", varl, var2); Just randomly chosen

NESO ACADEMY
RECALL THESE CODE SNIPPETS

printf("leso Academ); From Lecture 2

printf(k, var); From Lecture 4

printf(kd %á") var1, var2); Just randomly chosen

%d is a placeholder for variable "d means decimal


NESO ACADEMY
RECALL THESE CODE SNIPPETS

printf(leso Academyu); From Lecture 2

"CAUsers\jaspr\Downloads\C programs of dennis ritchie\pit

printf(D, v4Process returned e (exe) execution time :e.e:


Press any key to continue.

printf("kd zác) vari, var2); Just randomly chosen

%d is a placeholder for variable "d means decimal


NESO ACADEMY
printf("%d %d (%dj', var1, var2 );

error: expected expression before ') token

NESO ACADEMY
View Search Project Buld Debug Fortran wmith Tools Tocls+ Plugins DosyBiods Settings Help

xprintf.c X

include <stdio.h>

int main ()

int twO 2, three 3, six 61


int result three)* six/three:
(two +

printf ("I am new to programming but I know how to write aríthmetic expressions like this: (%d + td) * td / td ", two, three, six, three) :
printf ("and the result of this expression is: td", result)

CAUsers\jaspr\ Downloads\C programs of dennis ritchielprintf.exe

I am new to programming but I know how to write arithmetic expressions like this: (2 + 3)6/3 and the result of this expression is: 1e
Process returned e (exe) execution time : 1.356 s
Press any key to continue.

Blocks x

ACADEMY
C

PROGRAMMING AND
(DATA|STRUCTURES
Fundamental Data Types
-
(part 1) integer
NESO ACADEMY
SIZE OF INTEGER

From Lecture 3- Introduction


to variables 16 bits
2 bytes
4 bytes = 32 bits

More the size,more content


it can hold.
2 bytes 4 bytes

Dependson the machine

NESO ACADEMY
WANNA KNOW SIZE PROGRAMMATICALLY?

Use "sizeof" operator

#include <stdio.h>
Note: sizeof is a unary operator
and not a function.
int main()
{
printf("%d", sizeof (int)); Output:
return 0;

Sizeof integer is 4 bytes in my machine. May be it is 2 bytes in your


machine.
NESO ACADEMY
RANGE

Range: upper and lower limit of some set of data.

For example: {0, 1, 2, 3, 4}

Range: 0 to 4

NESO ACADEMY
PREREQUISITES

Decimal number system: Human Understandable number system.


Also called as base 10 number system.
Range: 0 to 9
2 1

10 10 10

S 6 8

10 x 5 +10 6 + 1O x 8 = 500+60+8 = 568


x

NESO ACADEMY
PREREQUISITES

Binary number system: Machine Understandable number system.


Also called as base 2 number system.

Range: 0 to 1

3 2 1

222 2
110 0

3 2 1

2x 1 + 2 x 1 + 2x 0 +2 x 0 = 8 + 4 +0 + 0 =12

NESO ACADEMY
RANGE OF 4 BIT DATA?
3 2 1

22 2 2
4 bit data: Minimum Value =O

111 1 Maximum Value =15

Range of 4 bit data: O00 0 to 1 111


to 15

Formula. 2 - 1
NESO ACADEMY
RANGE OF INTEGER
n

Unsigned range: 0 to 65535 (by applying: 2 - 1)


Signed range: -32768 to +32767

2 bytes
[16 bits]
2's complement range: -(2
n-1
) to +(2
n-1

- )
n

Unsigned range: 0 to 4294967295 (by applying: 2 - 1)

Signed range: -2147483648 to +2147483647

4 bytes
[32 bits]
NESO ACADEMY

You might also like